Accepting input from console in Node.Js

In this post, we will demonstrate how to accept input and perform operation in node.js from a console. Node.js is an open-source, cross-platform runtime environment for developing server-side web applications. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop, IBM AIX, IBM System z and IBM i.

Screenshot:


The Code
var readline = require('readline');

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question("What is your name ? ", function(answer) {
  // TODO: Log the answer in a database
  console.log("Hello "+answer+" how are u ?");
  rl.close();
});
Got any doubts, just go ahead and comment them ! :)

Comments

Popular posts from this blog

Non Restoring Division Algorithm Implementation in C

Employee Management System Using Inheritance in Java

Bit Stuffing Code Implementation in Java