Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active October 27, 2021 12:55
Show Gist options
  • Save acidtone/d57f41d7c18d0d198263c7bc3ab230e3 to your computer and use it in GitHub Desktop.
Save acidtone/d57f41d7c18d0d198263c7bc3ab230e3 to your computer and use it in GitHub Desktop.
npm: Evaluating the status of an npm project

npm: Evaluating the status of an npm project

Example npm directory structure

project-root
├── node_modules
│   └── dependency-1
│   ├── dependency-2
    └── dependency-3
└── app.js
├── package-lock.json
└── package.json

Evaluating the status of a project

An npm project is a directory with a valid package.json file inside the root. From there, it's important to recognize the current state of the project before you can get to work.

                    package.json file?
                             |
                 ---------------------------
                |                           |
               Yes:                         No:
       are there dependencies?     initialize new project                             
                |
     -----------------------
    |                       |
    No:                    Yes:
get to work      node_modules directory?
                            |
               --------------------------------
              |                                |
             No:                              Yes:
     Install dependencies:                 get to work
        $ npm install

Are there dependencies?

Dependencies (if they exist) need to be installed and downloaded before a project will function properly. The surest way to check if a project has dependencies is to:

  1. Open package.json in your editor.

  2. Check if there is a non-empty dependencies object.

    Yes:

    "dependencies": {
      "express": "^4.17.1"
    }

    No:

    "dependencies": {}
    • Or dependencies doesn't exist.
  3. Similarly, is there a non-empty devDependencies object? These are dependencies needed for project development.

Note: New projects won't have dependencies. You need to install one first:

$ npm install <project-name>

Relevant resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment