Introduction to nodejs
what is nodejs?
Node.js is an open-source runtime environment that allows developers to run JavaScript on the server side, built on Chrome's V8 engine. It is event-driven and non-blocking, making it ideal for handling many simultaneous connections efficiently. With its powerful package manager, NPM, Node.js has a vast ecosystem of libraries for rapid development.
Installing nodejs
Installing Node.js
Node.js is a cross-platform runtime environment that can be installed on Windows, macOS, and Linux. Here are the steps for each operating system:
Windows
Download the Installer:
Visit the official Node.js website.
Click on the Windows installer to download the
.msi
file.
Run the Installer:
Open the downloaded
.msi
file.Follow the installation prompts, accepting the license agreement and selecting the default options.
Verify Installation:
Open Command Prompt.
Run the following commands to verify the installation:
node -v npm -v
macOS
Download the Installer:
Visit the official Node.js website.
Click on the macOS installer to download the
.pkg
file.
Run the Installer:
Open the downloaded
.pkg
file.Follow the installation prompts, accepting the license agreement and selecting the default options.
Verify Installation:
Open Terminal.
Run the following commands to verify the installation:
node -v npm -v
Linux
Using a Package Manager:
For Debian-based distributions (e.g., Ubuntu):
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt-get install -y nodejs
For Red Hat-based distributions (e.g., CentOS):
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash - sudo yum install -y nodejs
Verify Installation:
Open Terminal.
Run the following commands to verify the installation:
node -v npm -v
By following these steps, you can successfully install Node.js on Windows, macOS, and Linux.
Alternatively: You can use NVM
NVM (Node Version Manager) is a tool that allows you to install and switch between different versions of Node.js easily. This is useful for testing your applications on different Node.js versions or managing multiple projects that require different versions.
Installing NVM
Windows
Download and Install NVM for Windows:
Go to the NVM for Windows GitHub page.
Download the latest NVM-setup.zip file.
Extract the zip file and run the
nvm-setup.exe
installer.Follow the installation prompts, accepting the license agreement and selecting the default options.
Verify Installation:
Open Command Prompt or PowerShell.
Run the following command to verify the installation:
nvm -v
macOS and Linux
Install NVM:
Open Terminal.
Run the following command to download and install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Follow the on-screen instructions to complete the installation.
Load NVM:
Add the following lines to your
~/.bashrc
,~/.zshrc
, or~/.profile
file:export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Source the file to apply the changes:
source ~/.bashrc # or source ~/.zshrc # or source ~/.profile
Verify Installation:
Run the following command to verify the installation:
nvm -v
Using NVM
Install Node.js:
To install the latest version of Node.js, run:
nvm install node
To install a specific version of Node.js, run:
nvm install <version>
Switch Node.js Versions:
To switch to a different installed version of Node.js, run:
nvm use <version>
By following these steps, you can easily install and manage multiple versions of Node.js using NVM on Windows, macOS, and Linux.
Hope this article was helpful
Subscribe to my newsletter
Read articles from Muchael123 directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Muchael123
Muchael123
I am a frontend and mobile developer specializing in building responsive and dynamic applications using React and React Native. With React, I focus on creating efficient and scalable web applications, leveraging its component-based architecture to deliver seamless user experiences. On the mobile side, React Native allows me to develop cross-platform applications for both iOS and Android with a single codebase, maintaining performance and native-like interfaces. My expertise in these technologies enables me to create intuitive, high-performance apps that meet modern user expectations.