Package.Json in node js
NODE JS is an JavaScript run-time environment for executing JavaScript code. The package manager for node is npm(Node Package Manager). A Package manager is a collection of software tools which keeps track of what software is installed on your computer, and allows you to easily install new software, upgrade software to newer versions, or remove software that you previously installed. I talked about npm because it helps in creating package.json file. For more information visit https://docs.npmjs.com
First time I used node js in my 2nd year of graduation. I did build a basic chat application, but I did not understand why package.json is necessary in the project, from where I am getting the node module folder. But I did the mistake. Before starting Node JS applications development, I should have learnt some basics and importance of package.json file. It is very simple and interesting. Every Node JS application or module or package should contain this package.json file. Every NODE JS project should have this file in the root directory to describe its metadata in plain json object format. Why this json filename is package? It is because every Node Js platform manages every features as package.
Does package.json helps in the the execution of your project? No. Then who uses this file? NPM (Node Package Manager) uses this package.json file information about Node JS Application information or Node JS Package details. It contains the name, version, description, keyword, authors etc these are related to the Application information and dependencies and dev dependencies are related to the package details. This package.json file can be created by typing npm init in the terminal, it will ask you about the information of the project. When we need any package(need to install some dependencies) then we type npm install — save [dependency name] and npm install — save -dev [dev dependency name]. By doing so it will automatically be added in the package.json file.
We push the project on any version control like git, then we don’t push the node_module folder. Because that will be taken care by package.json. Whosoever wants to run the project then he should clone that project run npm install command, then all the dependencies and dev dependencies will be install locally for your project, and a node_module named folder will also be created. There is a script section in it, it is very powerful one can use it as a replacement of task runner for his project. This is the power of package.json which I missed to understand while doing my first node js project. But I’ll recommend every one to please first read about it then start you project, because that will be an amazing feeling.