”;
Node.js Environment Setup
This Node.js tutorial consists of a number of ready-to-run examples, so that the learn can understand the Node.js concepts by running the code. To be able to execute the example code, you can use our online Node.js environment, or install Node.js environment in your local machine.
Try it Option Online
You really do not need to set up your own environment to start learning Node.js. Reason is very simple, we already have set up Node.js environment online, so that you can execute all the examples in this tutorial online and learn through practice.
Try the following example using the Live Demo option available at the top right corner of the below code box (on our website)
/* Hello World! program in Node.js */ console.log("Hello World!");
When you click the Live Demo button, the online Node.js environment is opened in a new browser tab.
Feel free to modify any example and check the results with different options. For most of the examples given in this tutorial, you will find a Try it option, so just make use of it and enjoy your learning.
Local Environment Setup
If you are still willing to set up your environment for Node.js, this section will guide you. Node.js can be installed on different OS platforms such as Windows, Linux, Mac OS X, etc. You need the following tools on your computer −
-
The Node.js binary installer
-
Node Package Manager (NPM)
-
IDE or Text Editor
Binaries for various OS platforms are available on the downloads page of the official website of Node.js. Visit https://nodejs.org/en/downloadto get the list.
This page shows two sets of binaries for different OS platforms, one for the current or latest version, and the other a version with LTS (Long Term Support), that is recommended for a normal user. 32 bit and 64 bit installers as well as ZIP archives for Windows, macOS installer as well as tar archives and binaries for Linux OS on x64 and ARM architecture are available.
Installation on Windows
Assuming that you are working with Windows 10/Windows 11 powered computer, download the 64-bit installer for Windows: https://nodejs.org/dist/v20.9.0/node-v20.9.0-x64.msi, and start the installation b double-clicking the downloaded file.
The installation takes you through a few steps of the installation wizard. It also adds the installation directory of Node.js executable to the system path.
To verify if Node.js has been successfully installed, open the command prompt and type node -v. If Node.js is installed successfully then it will display the version of the Node.js installed on your machine, as shown below.
Installation on Ubuntu Linux
First, download the tar file corresponding to Linux binary (https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.xz) and then, extract the binary using the tar command −
tar -xf node-v20.9.0-linux-x64.tar.gz
Move the extracted files to the installation directory /usr/local/node-v20.9.0.
sudo mv node-<version> /usr/local/node-v20.9.0
Create a symlink to the executable in /usr/bin directory.
sudo ln -s /usr/local/node-v20.9.0/bin/node /usr/bin/node
You can now verify the correct installation with the following command −
node -v
Using Ubuntu package manager
Refresh your local package index first by the following command −
sudo apt update
Then install Node.js −
sudo apt install nodejs
As in above case, verify the installation
node -v
NPM (Node Package Manager) is included in Node.js binaries from its official website since Node version 0.6.0., so you are not required to install it separately.
You can use any text editor available in your OS (notepad in Windows, vi or nano in Ubuntu) to key-in and save the Node.js script. However, it is recommended that you use a suitable IDE for the purpose as it has several features such as syntax highlighting etc. VS Code is a popular source-code editor, which has out of the box support for JavaScript (and hence Node.js), which is highly recommended.
”;