Node.js is known as a robust, cross-platform, open-source runtime environment for JavaScript which executes JavaScript code outside browser. It is based on Chrome’s V8 JavaScript engine and widely used to develop scalable network applications.
Node.js is an essential tool in modern web development, due to its capability of handling concurrent connections efficiently making it suitable for such uses as chat services, online gaming applications and collaboration tools and its event driven architecture makes it scalable and performant especially for I/O bound (input/output) tasks this allows programmers use one language JavaScript enabling them utilize identical same syntax both on server-client sides. A lot of supporting software from a host libraries made possible via NPM. Node.js is considered as pivotal technology for quick, scalable and efficient web applications.
Features of node.js
-> Event-Driven Architecture
It uses an event-driven, non-blocking I/O model, which makes it lightweight and efficient.
-> Single Programming Language
Allows developers to write both client-side and server-side code in JavaScript.
-> NPM (Node Package Manager)
Node.js has a package manager which comes by the name NPM that hosts thousands of free libraries and plugins like Angular making that easy to develop robust front-end applications when using Linux.
-> Scalability
Designed to build scalable network applications, it can handle many connections concurrently.
-> Performance
Leveraging the V8 engine, it performs well for I/O-bound operations.
-> Large Ecosystem
The extensive library of modules provided by NPM significantly enhances the development process.
Prerequisites
- A Linux Distribution: It supports a variety of Linux distributions like Ubuntu, Debian, CentOS, Fedora, etc. To follow this steps you require Ubuntu 20.04 .
- Sudo Privileges: Administrative rights to install and manage software packages.
- Hardware Requirements:
- Processor: 1 GHz or faster CPU (single core or multi-core).
- Memory: Minimum 512 MB of RAM (1 GB or more recommended for better performance).
- Storage: At least 100 MB of free disk space for this installation. Additional space will be needed for project files and dependencies.
Start node.js Installation
Using the NodeSource Binary Distributions
1. Update Package Index:
apt update
2. Install NodeSource PPA
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
3. Install Node.js and NPM:
apt install -y nodejs
4. Verify Installation
node -v
npm -v
Install node.js using the Default Repository
- Update Package Index
apt update
2. Install the packages
apt install -y nodejs npm
3. Verify Installation
node -v
npm -v
Using NVM
- Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
2. Load NVM
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"
3. Install Node.js:
- List available versions:
nvm ls-remote
- Install the desired version (e.g., Node.js 16.x):
nvm install 16
- Set the default version:
nvm alias default 16
4. Verify Installation:
node -v
npm -v
Conclusion
By following any of the methods above, you can successfully install Node.js on your Linux system. Choose the method that best suits your needs, whether you prefer using the NodeSource binaries, the flexibility of NVM, or the convenience of the default repository. Each method ensures that Node.js and NPM are properly installed and ready to use for your development projects.