Node.js
Readline
Recherche…
Syntaxe
- const readline = exige ('readline')
- readline.close ()
- readline.pause ()
- readline.prompt ([preserveCursor])
- readline.question (requête, rappel)
- readline.resume ()
- readline.setPrompt (prompt)
- readline.write (data [, clé])
- readline.clearLine (stream, dir)
- readline.clearScreenDown (stream)
- readline.createInterface (options)
- readline.cursorTo (flux, x, y)
- readline.emitKeypressEvents (flux [, interface])
- readline.moveCursor (flux, dx, dy)
Lecture de fichier ligne par ligne
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('text.txt')
});
// Each new line emits an event - every time the stream receives \r, \n, or \r\n
rl.on('line', (line) => {
console.log(line);
});
rl.on('close', () => {
console.log('Done reading file');
});
Inviter l'utilisateur à entrer via l'interface de ligne de commande
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What is your name?', (name) => {
console.log(`Hello ${name}!`);
rl.close();
});
Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow