project-root
├── node_modules
│ └── dependency-1
│ ├── dependency-2
└── dependency-3
└── app.js
├── package-lock.json
└── package.json
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
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:
-
Open
package.json
in your editor. -
Check if there is a non-empty
dependencies
object.Yes:
"dependencies": { "express": "^4.17.1" }
No:
"dependencies": {}
- Or
dependencies
doesn't exist.
- Or
-
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>