Registry / devops / restore-cursor

restore-cursor

JSON →
library5.1.0jsnpmunverified

Gracefully restore the CLI cursor on exit. The package automatically restores the cursor when a process exits, preventing hidden cursors from remaining hidden after crashes or interruptions. Latest version 5.1.0, maintained by Sindre Sorhus. Releases are stable and infrequent. Key differentiators: zero dependencies (v5+), proper TTY detection (no-op in non-TTY contexts), and simple imperative API. Pure ESM from v4, requires Node.js >=18 (v5).

npm install restore-cursor
INSTALL
IMPORT
SIG · RESTORE-CURSOR
R
restore-cursor
devopsjavascriptv5.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import restoreCursor from 'restore-cursor'
✗ const restoreCursor = require('restore-cursor')
Package is pure ESM since v4, so require() is not supported. Use dynamic import if needed in CJS: const restoreCursor = (await import('restore-cursor')).default;
restoreCursor
✓ import restoreCursor from 'restore-cursor'
✗ import { restoreCursor } from 'restore-cursor'
The default export is the function itself; there is no named export restoreCursor.
type
✓ import restoreCursor from 'restore-cursor'
✗ import type restoreCursor from 'restore-cursor'
restore-cursor ships TypeScript types, but the function is a default export (not a type). Use import type only for types, not for values.

Shows how to import and call restoreCursor to gracefully restore the cursor on exit. Demonstrates manual restore and automatic cleanup.

import restoreCursor from 'restore-cursor'; // Hide cursor (e.g., for a spinner) process.stdout.write('\u001B[?25l'); // ... do work (if the process crashes, cursor is restored automatically) // Restore cursor manually restoreCursor(); // Or let the cleanup happen on exit
Debug
Known issues
breakingThis package is now pure ESM. It cannot be require()'d from CommonJS.
fix
Use dynamic import() or switch to ES modules.
affects: >=4.0.0
breakingRequires Node.js 18 or later.
fix
Upgrade Node.js to >=18 or use v4.x (which requires Node.js 12.20).
affects: >=5.0.0
breakingNo longer prints control codes to non-terminal outputs.
fix
If you rely on cursor restore in non-TTY contexts, you may need to handle that manually.
affects: >=5.0.0
gotchaCalling restoreCursor() multiple times or when cursor was not hidden has no effect, but is safe.
fix
No action needed; it is idempotent.
affects: all
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using require() on a package that is pure ESM (v4+).
fix
Use dynamic import: const restoreCursor = (await import('restore-cursor')).default;
SyntaxError: Unexpected token 'export'
Trying to import a package using ESM in a CommonJS environment without proper configuration.
fix
Set "type": "module" in package.json or use .mjs extension.
Upgrade
Version history
5.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
restore-cursor — npm install restore-cursor · libregistry