Javascript: What is package.json in any node JS project?

This post is taken from LinkedIn

What is package.json in any node JS project?
package.json is the heart of any Node.js project. Every Node JS project should have this file at the root directory.

This file contains:
• All the packages/modules needed for a Node JS project and their requested versions.
• Several different directives or elements that tell NPM “How to handle the project” like scripts that can be run to automate tasks within the project.
• All the metadata for a project, such as a name, the author, the license, etc.
It makes your build reproducible, and therefore easier to share with other team members.

How we can generate it (package.json)?

  1. Using “npm init”:
    Running this command (‘npm init’) will set up a new NPM package. On initializing, you will be prompted to enter a few answers. Once you answer those and if it worked successfully, you should see a package.json at the root directory.

    Note* The fastest way to initiate a project is using the init command and the -y flag, which answers yes to all the questions:
Command: npm init -y

2. Create on your own: We can manually create a file “package.json” in the root folder of Node Project but make sure it has the same file name and it should have the same case “package” and the same file extension “.json”.

No alternative text description for this image

Leave a Reply