Input

Learn about various input methods in Node.js.

We'll cover the following...

Command line input

Let’s start with the most basic form of input, the command line input. Depending on how much you have used a terminal before, you may or may not be familiar with passing input to a program using the terminal. Let’s see how we do that first.

Suppose we have a simple program called app.js. This program prints out whatever you pass to it. You can pass it arguments by simply writing them after the program’s name in the terminal. Try it out with the command node app.js Hello. Hit the RUN button to get started.

console.log('Hey there,' , process.argv[2]); 
//  process.argv.forEach((val, index) => {
//   console.log(`${index}: ${val}`);
// });
Hit the RUN button to update your code before running it in the terminal

In this simple example, it is just one line of code. You might remember the console.log from the Hello World in the first lesson ...