Do you know that, we can add package names to packages.json file while install using npm ( Node Package Manager)
Wanna learn how to add a package file to Node project. Here it is
- Auto generate package.json file for Nodejs project
Nodejs project is the easiest and fastest way to create web applications. A package.Json file is the configuration file for the Nodejs project, it included all the information regarding the project. The dependencies, developer dependencies, starting scripts and so on. We can manually add a package file to our project. The structure of a minimal package file will be as follows.
{ "name": "Project Name", "version": "1.0.0", "description": "Description of your Project", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Developer Name", "license": "ISC" }
Auto generate package file
Node Package Manager can auto generate the package file by issuing the following command on Terminal
npm init
- npm will pull few question and answer them or leave it for default and then finally we will get the package.json file.
For this we have to use npm install <package-name> –save
npm install express --save
In your package file it will show as
"dependencies": { "express": "^4.17.1", "socket.io": "^3.0.1" }
Uninstalling will also remove it from the dependency list.
Developer dependecies
Packages which are used only for at the time of development are called developer dependecies. We can add developer dependencies by adding an option with Install save option as -dev. nodemon is an ideal example for development dependency.
</p> npm install nodemon --save-dev <p>