Package.Json in node js
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.