0% found this document useful (0 votes)
8 views2 pages

Practical 4

Uploaded by

Gnotra Payal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Practical 4

Uploaded by

Gnotra Payal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical 4

How to deal with Node package manager

1. Install NPM

NPM comes with Node.js, so start by installing Node.js:

1 .Download Node.js from Node.js Official Website.

2 .Verify Installation: using command


node -v
npm -v
2. Set Up Your Project
Create a new folder and initialize an NPM project using commands:
mkdir my-project
cd my-project
npm init

● This creates a package.json file that keeps track of your project and its dependencies.
● Use npm init -y for a default package.json.

3. Install Packages
Install dependencies needed for your project using commands:
npm install <package-name>
● Example: npm install express
● This creates a node_modules folder and updates dependencies in package.json.

4. Manage Packages

a) List Installed Packages using command:


npm list

b) Uninstall a Package

npm uninstall <package-name>

c) Update Packages using command:

npm update <package-name>

5. Use Scripts

Scripts are defined in the scripts section of package.json.

Add a script in package.json:


"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
}
Run a script using command:
npm start # Runs the 'start' script
npm run dev # Runs the 'dev' script

7. Handle Security Issues


Audit dependencies for vulnerabilities:
npm audit
npm audit fix

8. Explore NPM Commands


a. Check NPM usage:
npm help
b. Install all project dependencies:
npm install
C .Publish your package:
npm publish

You might also like