Installing packages in Node.js is straightforward using npm (Node Package Manager) or yarn. Here's how you can do it:
- Install project ( npm init -y )
- Install a package ( npm install )
- Install a package as a development dependency ( npm install --save-dev )
- Install a package globally ( npm install -g )
- To save the package as a dependency ( npm install --save )
- To update all packages ( npm update )
{
"name": "my-node-app",
"version": "1.0.0",
"description": "A sample Node.js application",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo "Error: no test specified" && exit 1"
},
"dependencies": {
"express": "^4.17.1",
"mongoose": "^5.13.2"
},
"devDependencies": {
"nodemon": "^2.0.12",
"jest": "^27.0.6"
}
}
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex