Related Tags

node.js

# How to use Readline.moveCursor() in Node.js

readline.moveCursor() moves the cursor relative to its current position.

## Prototype

readline.moveCursor(stream, dx, dy[, callback])


## Parameters

• stream<stream.Readable>: The stream to read from.
• dx<number>: Relative distance from the current position in the direction of $x$.
• dy<number>: Relative distance from the current position in the direction of $y$.
• callback<function>: The function that is invoked after the operation completes.

## Return value

readline.moveCursor() returns a boolean; it returns false if the stream expects the calling code to wait for the drain event to be emitted. Otherwise, readline.moveCursor() returns true.

## Code

In the code below, we create an instance of the interface. We associate it with the standard input for the Readable stream and the standard output for the Writeable stream.

The readline.moveCursor() method is used to move the cursor to the desired location. After this, we can print the location coordinates on the screen.

const readline = require('readline');

input: process.stdin,
output: process.stdout
});

console.log("dx = 5, dy = 5");
rl.close();

RELATED TAGS

node.js

CONTRIBUTOR