This article will go through the following points,
- Prerequisite
- Install Node.js Modules Intellisense extension in Visual Studio Code
- What is Node.js Modules Intellisense extension in Visual Studio Code?
- What is Package-lock.json?
- Install ReadLine Package
- What is ReadLine Package?
- Console Application Overview
- Console Application code and output.
Prerequisite
Software / Program Required
- Node JS
- Visual Studio Code
Packages Required
- Readline
Install Node.js Modules Intellisense extension in Visual Studio Code
What is Node.js Modules Intellisense extension in Visual Studio Code?
This extension will provide intellisense of node js while writing code in Visual Studio code.
What is Package-lock.json?
Package-lock.json file automatically gets generated during any modification/update in node_modules. You can check in this file for packages already installed.
For more details visit the following link:
https://docs.npmjs.com/files/package-lock.json
Install ReadLine Package
If the READLINE package is not installed than you can install it with following command.
COMMAND: npm install readline
What is ReadLine Package?
ReadLine package module provides an interface for reading data from a Readable stream.
To learn more about ReadLine package please visit the following link:
https://nodejs.org/api/readline.html#readline_readline
Console Application Overview
In this article we are going to create a console application in NODE JS.
Prompt the user to enter following fields data
- Enter Your Name
- Enter Your Age
- Enter Your Email ID
- Enter Your Mobile No.
Rules, Logic and Condition in Entry
- If Age is less than < 18 it will return and display the message:
"Minimum required 18 years and you age is 16 , You should wait at least 2 year(s) more."
- If Age is greater than > 18 it will return and display the message:
“Great <UserName> you can signin.”
“User Name : <UserName>”
“Age : <UserAge> “
“Email ID : <UserEmailID>”
“Mobile : <UserMobile>”
NodeJS to run javascript code on server side.
Console Application Code
- var rl = require("readline");
- var prompts = rl.createInterface(process.stdin, process.stdout);
- prompts.question("Enter Your Name? ", function(username) {
- prompts.question("Enter Your Age ? ", function(userage) {
- prompts.question("Enter Your Email ID? ", function(emailid) {
- prompts.question("Enter Your Mobile No.? ", function(mobile) {
- var message = "";
- if (userage > 18) {
- message = "\n\n Great! " + username + "\n\n You can signin." + "\n\n User Name : " + username + "\n\n Age : " + userage + "\n\n Email ID : " + emailid + "\n\n Mobile : " + mobile;
- } else {
- message = "Minimum required 18 years and you age is " + userage + " , You should wait at least " + (18 - userage) + " year(s) more.";
- }
- console.log(message);
- process.exit();
- });
- });
- });
- });
OUTPUT
In output section I have given two examples.
In the first example the age is 9 years and in the second example the age is 20 years.
First Example
Second Example
Happy Coding…