NPM in Linux – Basic Commands & Usage Guide

NPM is a package manager that helps you install and manage Node.js libraries and development tools on Linux systems. It is commonly used for building web applications, running JavaScript projects, and handling project dependencies easily through the terminal. NPM terminal commands help you quickly download packages, update tools, and manage JavaScript projects more efficiently. Here are the installation and usage commands for NPM on Linux.

Installation Commands

Update system packages:

sudo apt update && sudo apt upgrade -y

Install Node.js and NPM:

sudo apt install nodejs npm -y

Check Node.js version:

node -v

Check NPM version:

npm -v

Basic NPM Commands

Initialize a Node.js project:

npm init

Initialize project with default settings:

npm init -y

Install a package:

npm install express

Install package globally:

npm install -g nodemon

Install all dependencies:

npm install

Remove a package:

npm uninstall express

Update packages:

npm update

List installed packages:

npm list

List globally installed packages:

npm list -g --depth=0

Run project script:

npm start

Usage Guide

Create a new project folder:

mkdir myproject

Open project folder:

cd myproject

Create package.json file:

npm init -y

Install Express framework:

npm install express

Create JavaScript file:

nano app.js

Example Express server code:

const express = require('express');

const app = express();

app.get('/', (req, res) => {
  res.send('NPM Server Running');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Run Node.js application:

node app.js

Open in browser:

http://localhost:3000

These are some useful usage and basic NPM commands for the Linux terminal that help you install libraries, manage dependencies, and start building modern web applications more efficiently.

See also  Basic Termux Commands List for Beginners [With PDF Download]
SHARE THIS POST:

Leave a Reply

Your email address will not be published. Required fields are marked *