Node.js Introduction

  • Post category:Node
  • Reading time:3 mins read

So, before start learning node.js, I am assuming you already know Javascript. So, the first thing that you need to do is install node.js on your system. After installing node.js you can check whether it is correctly installed or not using the node -v command, which will show you the node version installed on your system.

You can write node -v command either in your VS code terminal or using the command prompt. If you are using a MacBook then you can use the terminal as well for checking the node version.

Node.js Introduction

Node.js is a Javascript run time, which is built on google’s open-source v8 js engine. But what does this mean? Let me explain to you. All browsers by default support JS but what if I need to run the JS program outside of the browser? Here comes node.js, It is just like a container-like a environment in which a program written in js can be executed. Node.js is single threaded.

Node.js Pros

  • If you already know JS, then it is easy for you to learn node.js, and you can also learn react.js for the front-end.
  • JS across the entire stack, so easy to learn, and the same programming language.
  • Perfect for building fast and scalable apps.
  • You can find huge open-source packages which are NPM, and it is available for free.

Running a simple code in the terminal

  • Open terminal in VS Code
  • Write node and hit enter
  • We can now write a js code just like in a normal terminal

Example:

writing node js program in terminal

Let me explain the above screenshot.

  • So, I run the node command in the terminal. Now, I am able to write JS programs in the terminal.
  • 20 + 40 will give you 60 output, and 60 multiply 2 will give you 120.
  • _ + 20 will give 140, here underscore carries the previous value which is 120 (see in the above screenshot).
  • The same case in the next line _ carries a 140 value, and 140-40 will give you 100.

Some commands that you need to know in this post

  • .exit – This command will exit the node
  • command + K (for MacBook) – to clear the terminal

To check methods and properties of String, Number, etc, You can write a command String. or Number. and hit the tab button. It will show all the methods/properties available to the String, Number, etc

node js command for beginners

Share this