How to Run Node.js on Windows, macOS, Linux? (2024)

If you're going to use the Node.js environment for the first time in back-end JavaScript development, you need the right guidance to run it on your computer.

36.19% of the skilled developers are using Node.js today for server-side scripting and developing responsive websites that run user requests on the web server and not on the client side or web browser. This not only reduces the loading time of any website by 50-60% but also increases the overall performance of all types of applications by 50%.

That's why global companies use Node.js, and the number is increasing every day. We've curated a step-by-step guide on how to run Node.js on Windows, macOS, and Linux, along with other necessary details.

Let's get started!

What is Node.js?

Node.js is an open-source JavaScript runtime environment designed on Chrome’s V8 JavaScript engine. It renders cross-platform support to help the developers test and debug their code within a virtual domain irrespective of their operating system. Thus, developers can now perform server-side and client-side scripting using the same language, JavaScript.

Front-end developers use JavaScript to build interactive website UI, but that only works on the client-side or web browser. Node.js brings all the capabilities to JavaScript required for using it on back-end development, the server-side part of a web app architecture, and the serverless one.

Hence, you can understand the growing demand for a Full Stack JavaScript developer; learning the Node.js program is the first step toward becoming one.

Now, let’s start with how to run Node.js on different operating systems.

How to Install Node.js on Windows?

To install Node.js on your Windows PC, you need to first download the Windows Installer (.msi) package from its official website. This package contains all the files required for installing, updating, and modifying the downloaded Node.js version as per your preferences. So, check out the below steps to learn how to start Node.js and work seamlessly with it on your PC.

Note:The .msi package contains npm (Node.js package manager) also. Thus, you don't have to install npm separately on your PC.

System Requirements

  1. Windows 10 OS
  2. 4 GB RAM
  3. 10 GB free storage
  • First, click here to visit the Node.js official website.
  • Next, navigate to Windows Installer (.msi) and download either the 32-bit or 64-bit version according to the architecture of your PC.
  • Now, double-click on this .msi setup file to start with the installation.
  • On the Node.js Setup window, check the box next to I accept the terms in the License Agreement.
  • Then, hit the Next button.
  • Browse and select the path now where you want to install Node.js locally and click Next.
  • On the Custom Setup window, make changes if you have any preference; if not, continue by clicking the Next button.
  • If you want to automatically install necessary tools for native modules from Node.js, check the box on this screen and click Next.
  • Finally, Node.js will prepare the installation; click the Install button on the Ready to install Node.js window.
  • Now, Node.js will be installed on your system within a few minutes; click the Finish button to close the installer.
  • You can verify the installation by running the below command in Command Prompt as an administrator,
node --version 
  • You can also check the npm version for Node.js with the following command,
npm --version

How to Run Node.js Application Code on Windows?

After you install Node.js on your computer, 'node' will be registered as an internal command on your system. Then, you can easily run Node.js projects on Windows using Command Prompt. Check the below steps to learn how to run scripts on Node.js while using Windows OS.

  • First, open Command Prompt with administrative privileges.
  • Next, type in the below command and hit enter to create the test-node.js file (you can choose any name).
echo console.log(1+1); >> test-node.js
  • This file will contain a simple application and print out 1+1.
  • Next, type 'node' along with the name of the application ('test-node.js' in this case) and press Enter.
node test-node.js
  • Now, the result of running the app will be displayed on your command prompt.

How to Install Node.js on macOS?

To install Node.js on macOS, you need to download the suitable installer package manager from the official website first. This package also contains an npm repository, so you don't need to install it separately on Mac. Take a look at the steps below to know how to start Node.js on macOS.

System Requirements

  1. macOS 10.10 or higher
  2. 4 GB RAM
  3. 10 GB free Storage
  • First, click here to visit the Node.js official website.
  • Next, download the 64-bit macOS Installer (.pkg) file on your computer.
  • Double-click on the package; the Install Node.js window will open now.
  • Click the Continue button to start the installation process.
  • Now, go through the Software License Agreement and click Continue.
  • You'll get a prompt next; click the Agree button to accept the software license terms.
  • Then, select a destination where you want to install Node.js and click Continue.
  • On the next screen, hit the Install button and wait for it to get finished.
  • When done, click the Close button to turn off the installer.
  • Next, press the Command + Space buttons to open the search tab.
  • Search for 'terminal' and click on it from the results to open.
  • Now, check the Node.js version you've installed by entering the below command,
node --version
  • Then, check the npm version with the below command,
npm --version

How to Run Node.js Files on macOS?

If you've already installed Node.js on macOS, you can run any file written on JavaScript. But for that, first, you have to create a file with a specific command. Here we've mentioned a step-by-step guide to help you know how to run the Node.js application on Mac; read now.

  • First, press the Command + Space button to open Spotlight Search and type in 'terminal'.
  • Next, open Terminal from the search results, enter the following command to create a file 'test-node.js' (you can choose any name), and hit Return,
echo "console.log(1+1);" >> test-node.js
  • It'll contain an application, which will print out result 1+1.
  • Now, type in the below node command along with the file name and press Return.
node test-node.js
  • You'll get the output now in the terminal.

How to Run Node.js on Linux?

Being an open-source operating system, Linux has a wide range of distributions. Node.js installation is different on each Linux distro. You can check the Node.js Binary Archive to get the exact installation method for the system you're using. We’ve prepared this tutorial on how to start Node.js on a Ubuntu system. Go through now.

  • First, install the curl command-line utility on your Linux; enter the below command in a terminal window for that.
sudo apt install curl
  • It may ask for your system password to confirm if you've admin access.
  • Once you enter that, the curl command will be installed.
  • Next, you need to copy the installation command for your Linux distro from the Node.js Binary Archive page and paste it into the terminal window.
  • For Ubuntu, we've used the below command (replace ‘14.x’ with the Node.js version you require.)
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
  • Now, the Node.js installation process will run.
  • When all Node.js libraries are installed on your system, enter the below command,
sudo apt-get install -y nodejs
  • Finally, Node.js will be installed on your system.
  • Enter the Clear command now to clear your terminal.
  • Now, confirm your Node.js version by entering the below command in a terminal,
Node --version
  • You can also check your npm version with the below command,
npm –version

How to Install Nodemon?

Node Monitor (nodemon) is a command-line tool that makes back-end development a lot easier while using Node.js. It automatically restarts your node application whenever any file changes are detected within the directory. If you've already installed Node.js and the npm package on your system, you can install nodemon in two different ways.

  • Install Nodemon Globally: To install nodemon globally, run the "npm install --global nodemon" command on your system. It'll be installed on your system path, enabling you to use the "nodemon" command directly.
  • Install Nodemon Locally: To install nodemon locally as a development dependency, run the "npm install --save-dev nodemon" command. If you perform a local installation, you can't use "nodemon" directly on the command line as you'll get the "command not found" output. You can only run it by calling it from within an npm script, i.e., npm start, or using npx nodemon.

How to Run Node.js Project?

You can run Node.js projects using the node command. But first, you need to install Node.js on your system to get the node command. Next, you've to create the Node.js file using the methods mentioned above. Then, you can execute the file in the shell, even with certain modifications, if you want to. [We've used the "test-node.js" file for this tutorial.]

  • You can call your application file by typing in the below node command,
node test-node.js
  • If you want to tell Node.js how to run the script using which interpreter, you can embed the node command with a 'shebang' line into your JavaScript; enter the below command for that.
#!/usr/bin/node
  • In case your system doesn't have the node within the bin folder, it must have env, and you can instruct your OS to run the script with env while keeping the node as a parameter; use the below commands for that. [Enter your script in the place of the demo code.]
#!/usr/bin/env node// demo code

Note: The "shebang" is the first line in your JavaScript file. It can be modified to tell your OS which interpreter to use while running a script. But your file should have executable permission to use a shebang line. Use the below command to give executable permission to your file.

chmod u+x test-node.js

How to Install Node.js with nvm Installer?

Node.js Version Manager (nvm) enables you to install and manage different versions of Node.js on a single local system. Even if you need a particular version, you can use the nvm installer to get that, as nvm will help you switch between all the existing versions on the system depending on what your project demands.

Here we've provided a step-by-step guide on how to install Node.js with the nvm installer on macOS and Linux; have a look. If you're using a Windows PC, check this guide.

  • First, install curl on your system by entering the below command in a terminal window.
$sudo apt update && sudo apt install curl -y
  • Next, download the nvm installation script by using the below command (replace v0.35.0 with the latest nvm version.)
$curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh
  • Now, type the below command and hit enter to run the install script.
bash install_nvm.sh
  • To apply the changes on your profile and set the right environment variables for running nvm, enter the below command.
CentOS, Redhat, and Fedora users:$source ~/.bashrcDebian users:$source ~/.profile
  • Once done, preview the list of available Node.js versions by entering the below command.
$ nvm ls-remote
  • Now, choose a specific version and install it by entering the below command (replace 16.14.0 with your required Node.js version.)
$nvm install v16.14.0

How to Install npm in Visual Studio Code?

Visual Studio Solution has been helping full-stack developers with easy npm package management on Node.js. You can issue npm commands through its intuitive UI and perform different development tasks. Here we've mentioned how to install npm in Visual Studio Code using an extension, Solution Explorer, which adds a Visual Studio Solution File explorer panel within it. Let's start!

  • First, you must access the npm package installation window from Solution Explorer.
  • For that, you've to right-click on the npm node in the project and choose to Install New npm Packages from the pop-up window.
  • In the installation window, you can pick any package and specify Options for it as mentioned below:
    • Dependency type - Choose Standard if you want the package to be a runtime dependency and Development if you want to use it for development only.
    • Add to package.json - Check the box next to (recommend).
    • Selected version - Select (latest).
    • Other npm arguments - If you want to install any specific version, add the value here.
  • Once done, click the Install Package button.
  • Next, navigate to View> Output to check the progress of the npm installation in the Output window.

How to Start Node Server?

You might know that Node.js can be used to run desktop app servers seamlessly. Here we've provided a guide on ‘Node.js on how to start a server’ and run it on your local system. Have a look and create your first Node.js web server.

  • First, visit this link and download the Node.js LTS version.
  • Next, check your node version by entering the below command,
node --version
  • Then, create a new folder using the below command (change testApp with your project),
mkdir testApp
  • Now, move to the just created folder using the below command,
cd testApp
  • After that, you have to initialize the npm package installation using the following command,
npm init -y
  • Now, create a .js file (test-node.js in our case) and write the following code to create a server and ask it to listen to a certain port that will preclude the HTTP library.
const http = require('http')const port = 8080// Create a server object:const server = http.createServer(function (req, res) {// Write a response to the clientres.write('Hello World')// End the responseres.end()})// Set up our server so it will listen on the portserver.listen(port, function (error) {// Checking any error occur while listening on portif (error) {console.log('Something went wrong', error);}// Else sent message of listeningelse {console.log('Server is listening on port' + port);}})
  • After that, run the application by entering the below command,
  • node test-node.js
  • Now, launch your browser and visit http://localhost:8080/.
  • You must see the "Hello World" output.

How Does Node.js Work?

Node.js uses asingle-threadedevent loop model, which allows it to handle multiple concurrent requests quickly and without waiting. Incoming requests are sent into an event queue. If a request does not need blocking I/O, it is handledimmediately. A thread from the internal pool handles requests that require blocking I/O, such as database access, and returns the results to the event loop for client response. This design allows Node.js to outperform multi-threaded frameworks such as ASP.NET and Ajax in a variety of circ*mstances.

How to run Node.js effectively involves understanding its event loop and non-blocking I/O model. Node.jscontainsnpm, a package manager that hosts over 1,000,000 open-source packages and allows libraries to be easily shared,modified, and integrated. Thisgreatly simplifiesweb application development.Sign up forourJava full-stack developer courseto learn everything about this versatile platform and specialize in this single programming language, JavaScript, for front-end and back-end development.

Looking for the best Python course with placement? Look no further! Discover the power of Python with our unique and catchy content. Join us today and unlock endless possibilities in the world of programming. Don't miss out!

Conclusion

Running Node.js on different types of operating systems is simple because of its wide community support and detailed documentation. By following the methods indicated in this guide on how to run Node.js, you can install and configure Node.js on Windows, macOS, and Linux, allowing you to build and operate your applications across many platforms. Node.js' versatility and efficiency make it a good choice for a wide range of applications, including simple webpages and large network applications.

As you continue to experiment and build with Node.js, you'll appreciate its efficiency, speed, and the wide ecosystem of modules and frameworks that may enhance your development capability. Whether you're creating server-side applications, APIs, or full-stack projects, knowing Node.js will be a great asset to your programming toolset.

Now you know how to install Node.js on Windows, macOS, and Linux, along with all the basic knowledge you need to get started with back-end development. Sign up for our KnowledgeHut’s Node.js program to ace full-stack development.

How to Run Node.js on Windows, macOS, Linux? (2024)
Top Articles
A Profile of Intellectual Disability | Info for Parents and Teachers
Proxies For Bots | Proxyrack
How To Start a Consignment Shop in 12 Steps (2024) - Shopify
Dannys U Pull - Self-Service Automotive Recycling
122242843 Routing Number BANK OF THE WEST CA - Wise
Identifont Upload
From Algeria to Uzbekistan-These Are the Top Baby Names Around the World
Kobold Beast Tribe Guide and Rewards
Songkick Detroit
Weapons Storehouse Nyt Crossword
414-290-5379
Palace Pizza Joplin
Wnem Radar
Ivegore Machete Mutolation
Wgu Admissions Login
Missing 2023 Showtimes Near Landmark Cinemas Peoria
National Office Liquidators Llc
Royal Cuts Kentlands
Vigoro Mulch Safe For Dogs
Crawlers List Chicago
Phoebus uses last-second touchdown to stun Salem for Class 4 football title
Garnish For Shrimp Taco Nyt
Boston Dynamics’ new humanoid moves like no robot you’ve ever seen
Drift Hunters - Play Unblocked Game Online
Essence Healthcare Otc 2023 Catalog
Albert Einstein Sdn 2023
Meet the Characters of Disney’s ‘Moana’
Bra Size Calculator & Conversion Chart: Measure Bust & Convert Sizes
Arlington Museum of Art to show shining, shimmering, splendid costumes from Disney Archives
3 Ways to Drive Employee Engagement with Recognition Programs | UKG
Craigslist Efficiency For Rent Hialeah
Taylored Services Hardeeville Sc
Issue Monday, September 23, 2024
Shauna's Art Studio Laurel Mississippi
Moonrise Time Tonight Near Me
Ixl Lausd Northwest
The Ride | Rotten Tomatoes
Today's Final Jeopardy Clue
The Land Book 9 Release Date 2023
Hannibal Mo Craigslist Pets
Elgin Il Building Department
The Vélodrome d'Hiver (Vél d'Hiv) Roundup
Aliciabibs
Empires And Puzzles Dark Chest
Shell Gas Stations Prices
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
9:00 A.m. Cdt
What is 'Breaking Bad' star Aaron Paul's Net Worth?
From Grindr to Scruff: The best dating apps for gay, bi, and queer men in 2024
How to Do a Photoshoot in BitLife - Playbite
Nfhs Network On Direct Tv
Blippi Park Carlsbad
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 6042

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.