Skip to main content
REPLServer.prototype.defineCommand - node__repl.d.ts - Node documentation
method REPLServer.prototype.defineCommand

Usage in Deno

```typescript import { REPLServer } from "node:node__repl.d.ts"; ```
REPLServer.prototype.defineCommand(
keyword: string,
): void
The `replServer.defineCommand()` method is used to add new `.`\-prefixed commands to the REPL instance. Such commands are invoked by typing a `.` followed by the `keyword`. The `cmd` is either a `Function` or an `Object` with the following properties: The following example shows two new commands added to the REPL instance: ```js import repl from 'node:repl'; const replServer = repl.start({ prompt: '> ' }); replServer.defineCommand('sayhello', { help: 'Say hello', action(name) { this.clearBufferedCommand(); console.log(`Hello, ${name}!`); this.displayPrompt(); }, }); replServer.defineCommand('saybye', function saybye() { console.log('Goodbye!'); this.close(); }); ``` The new commands can then be used from within the REPL instance: ```console > .sayhello Node.js User Hello, Node.js User! > .saybye Goodbye! ```

Parameters

keyword: string
The command keyword (_without_ a leading `.` character).
The function to invoke when the command is processed.

Return Type

void