With 20+ yrs of industry experience in media, entertainment and web tech, Sachin brings expertise in hands-on training and developing forward-thinking, industry-centric curricula. 30k+ students have enrolled in his tech courses.
For enquiries call:
+1-469-442-0620
HomeBlogWeb DevelopmentHow to Run Node.js on Windows, macOS, Linux?
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. We've curated a step-by-step guide on how to run Node.js on Windows, macOS, and Linux, along with other necessary details. Have a look.
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 like Amazon, eBay, Netflix, Reddit, Tumblr, LinkedIn, PayPal, etc., use Node.js, and the number is increasing every day. 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. Let's get started!
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.
Node.js works on a 'single-threaded event loop' model. That means it can respond to concurrent requests from a single thread while dismissing the requirements of blocking it for one client request only. Whenever this framework receives an incoming request, it is placed in the event queue first, and then the processing starts. Now two instances can happen.
If the client request doesn't require any blocking I/O (Input/Output), it will be processed instantly, and the response will be sent back to the source.
When the request needs some blocking I/O operations, i.e., accessing the database or communicating with the external services, it first picks a thread from the internal thread pool and assigns the request to that thread. Now that particular thread will first process the request by performing the required blocking I/O operations. Then, it will prepare the response and send it back to the event loop to send it to the client finally.
Thus, Node.js can serve multiple client requests parallelly by placing them in the event queue and getting each of them processed through the event loop. That’s why you experience faster performance while working in this lightweight environment than using any multi-threaded request-response architecture like HTML, ASP.NET, Ajax, etc.
Node.js comes with a package manager, npm. It works as an index of the libraries created by the Node.js developers' community. These packages are easily shared, modified, and imported by other projects. Yes, the npm registry hosts over 1,000,000 open-source packages that provide optimal solutions that make developing new projects easier and improve the old ones at the same time.
Hence, you can use Node.js for easy web application developments. If you want more streamlined experience, you can change the source code of this open-source runtime environment and use it on your system. Sign up for our Java full-stack developer course to learn everything about this versatile platform and specialize in this single programming language, JavaScript, for front-end and back-end development.
Now, let’s start with how to run Node.js on different operating systems.
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
node --version
npm --version
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.
echo console.log(1+1); >> test-node.js
node test-node.js
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
node --version
npm --version
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.
echo "console.log(1+1);" >> test-node.js
node test-node.js
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.
sudo apt install curl
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Node --version
npm –version
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.
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.]
node test-node.js
#!/usr/bin/node
#!/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
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.
$sudo apt update && sudo apt install curl -y
$curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh -o install_nvm.sh
bash install_nvm.sh
CentOS, Redhat, and Fedora users: $source ~/.bashrc Debian users: $source ~/.profile
$ nvm ls-remote
$nvm install v16.14.0
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!
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.
node --version
mkdir testApp
cd testApp
npm init -y
const http = require('http') const port = 8080 // Create a server object: const server = http.createServer(function (req, res) { // Write a response to the client res.write('Hello World') // End the response res.end() }) // Set up our server so it will listen on the port server.listen(port, function (error) { // Checking any error occur while listening on port if (error) { console.log('Something went wrong', error); } // Else sent message of listening else { console.log('Server is listening on port' + port); } })
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!
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.
Yes, Node.js can easily run on Linux. Since it's an open-source platform, you can modify the source code and use it on your Linux distro to get the best experience. Find the exact installation command for the Linux distro you're using from here.
Check the installation method we've mentioned above to run Node.js on Ubuntu.
To run a Node.js file on Mac, you need to download the installer package from the Node.js official website first and set it up by following the on-screen instructions on your system. Then, you've to create a .js file and run it using the node command on Mac.
Check the above-mentioned step-by-step guide to install Node.js on macOS and run a file on it.
To run npm on Windows, you need to download the Node.js installer package first. The npm package comes with the installation package only. So, installing Node.js on your PC will automatically install npm alongside. Check the above section to know how to run Node.js on Windows.
You need to use specific commands to install npm on different Linux distros. Check the complete list below- (use the commands without quotation)
That's all! Our guide on how to install Node.js on Windows, macOS, and Linux ends here. If you've further queries, drop us a comment. Thanks for reading!
Yes, you can run Node.js on Windows. You need to download the 32-bit/64-bit installer package first from the Node.js website and install it on your PC. You can find the exact installation method in the above section.
Name | Date | Fee | Know more |
---|