
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@inquirer/external-editor
Advanced tools
Edit a string with the users preferred text editor using $VISUAL or $ENVIRONMENT
@inquirer/external-editor is a Node.js package that allows users to open an external text editor from a command-line interface (CLI) application, enabling them to edit text in their preferred editor and then return the edited text back to the application.
Launch External Editor
This feature allows you to launch the user's default text editor from a Node.js application. The `edit` function opens the editor, waits for the user to finish editing, and then returns the edited text. This is useful for applications that require complex text input that is more easily handled in a full-featured text editor.
const { edit } = require('@inquirer/external-editor');
const userInput = edit();
console.log('User input:', userInput);
Handle Editor Errors
This feature provides an asynchronous way to handle the external editor process, including error handling. The `editAsync` function takes a callback that receives any errors and the user's input. This is useful for non-blocking operations in applications that need to handle potential errors when launching or using the external editor.
const { editAsync } = require('@inquirer/external-editor');
editAsync((err, userInput) => {
if (err) {
console.error('Error:', err);
} else {
console.log('User input:', userInput);
}
});
The `external-editor` package is a similar library that allows launching an external text editor from a Node.js application. It provides both synchronous and asynchronous methods to open the editor and retrieve the edited text. Compared to @inquirer/external-editor, it offers similar functionality but is not specifically tied to the Inquirer.js ecosystem.
The `edit-string` package provides a simple interface to open a string in the user's default text editor and return the edited result. It is a lightweight alternative to @inquirer/external-editor, focusing on simplicity and ease of use without additional features like error handling or asynchronous operations.
@inquirer/external-editor
A Node.js module to edit a string with the user's preferred text editor using $VISUAL or $EDITOR.
[!NOTE] This package is a replacement for the unmaintained
external-editor
. It includes security fixes.
npm | yarn |
---|---|
|
|
A simple example using the edit
function
import { edit } from '@inquirer/external-editor';
const data = edit('\n\n# Please write your text above');
console.log(data);
Example relying on the class construct
import {
ExternalEditor,
CreateFileError,
ReadFileError,
RemoveFileError,
LaunchEditorError,
} from '@inquirer/external-editor';
try {
const editor = new ExternalEditor();
const text = editor.run(); // the text is also available in editor.text
if (editor.lastExitStatus !== 0) {
console.log('The editor exited with a non-zero code');
}
// Do things with the text
editor.cleanup();
} catch (err) {
if (err instanceof CreateFileError) {
console.log('Failed to create the temporary file');
} else if (err instanceof ReadFileError) {
console.log('Failed to read the temporary file');
} else if (err instanceof LaunchEditorError) {
console.log('Failed to launch your editor');
} else if (err instanceof RemoveFileError) {
console.log('Failed to remove the temporary file');
} else {
throw err;
}
}
Convenience Functions
edit(text, config)
text
(string) Optional Defaults to empty stringconfig
(Config) Optional Options for temporary file creationCreateFileError
, ReadFileError
, or LaunchEditorError
, or RemoveFileError
editAsync(text, callback, config)
text
(string) Optional Defaults to empty stringcallback
(function (error?, text?))
error
could be of type CreateFileError
, ReadFileError
, LaunchEditorError
, or RemoveFileError
text
(string) The contents of the fileconfig
(Config) Optional Options for temporary file creationErrors
CreateFileError
Error thrown if the temporary file could not be created.ReadFileError
Error thrown if the temporary file could not be read.RemoveFileError
Error thrown if the temporary file could not be removed during cleanup.LaunchEditorError
Error thrown if the editor could not be launched.External Editor Public Methods
new ExternalEditor(text, config)
text
(string) Optional Defaults to empty stringconfig
(Config) Optional Options for temporary file creationCreateFileError
run()
Launches the editor.
LaunchEditorError
or ReadFileError
runAsync(callback)
Launches the editor in an async way
callback
(function (error?, text?))
error
could be of type ReadFileError
or LaunchEditorError
text
(string) The contents of the filecleanup()
Removes the temporary file.
RemoveFileError
External Editor Public Properties
text
(string) readonly The text in the temporary file.editor.bin
(string) The editor determined from the environment.editor.args
(array) Default arguments for the bintempFile
(string) Path to temporary file. Can be changed, but be careful as the temporary file probably already
exists and would need be removed manually.lastExitStatus
(number) The last exit code emitted from the editor.Config Options
prefix
(string) Optional A prefix for the file name.postfix
(string) Optional A postfix for the file name. Useful if you want to provide an extension.mode
(number) Optional Which mode to create the file with. e.g. 644dir
(string) Optional Which path to store the file.Everything is synchronous to make sure the editor has complete control of the stdin and stdout. Testing has shown async launching of the editor can lead to issues when using readline or other packages which try to read from stdin or write to stdout. Seeing as this will be used in an interactive CLI environment, I made the decision to force the package to be synchronous. If you know a reliable way to force all stdin and stdout to be limited only to the child_process, please submit a PR.
If async is really needed, you can use editAsync
or runAsync
. If you are using readline or have anything else
listening to the stdin or you write to stdout, you will most likely have problem, so make sure to remove any other
listeners on stdin, stdout, or stderr.
Copyright (c) 2025 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.
FAQs
Edit a string with the users preferred text editor using $VISUAL or $ENVIRONMENT
The npm package @inquirer/external-editor receives a total of 8,258,885 weekly downloads. As such, @inquirer/external-editor popularity was classified as popular.
We found that @inquirer/external-editor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.