Create a new folder anywhere on your machine. Open command prompt and navigate to the newly created folder. Type command code . (code space dot) which will open VS Code into this folder. You can use any editor such as Atom, sublime etc., or a text editor such as notepad also. It is not necessary to use VS Code.
Example, create a folder named node anywhere on your machine. Open VS Code in this folder and click new file icon as shown in the image below.
first node program

For opening VS Code in a folder, navigate to the folder location in command prompt and type code . and hit enter.

Name the new file as firstprogram.js. Note that the file ends with a .js extension. Reason is that node comprises of a javascript engine and hence it only understands js files.
In the newly created file, write the below code.

function sayHello() {
    console.log('Learning Node.js!!!');
}

// call function
sayHello();

Above code creates a simple javascript function and calls it.
Now in the command prompt which is open at the location of the above file, type node firstprogram.js
You will see an output as below.

Learning Node.js!!!

Note that all the code written in node is in javascript, so you need to be familiar with javascript for learning node. You can learn javascript here.
0

Leave a Reply