0

I am trying to start a new project that require node.js. After I create a folder, I am trying to make node_modules to show up in my project folder. Therefore, I use

npm init

and then, I use

npm install

after the installing it, I realized that my node_modules folder is empty, so I checked out the package.json. I realized that there is no dependencies

is there any way to fix this problem?

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
Mike Lo
  • 55
  • 1
  • 5
  • npm install package_you_need --save-dev. see [doco](https://docs.npmjs.com/cli/install) – lloyd Jan 10 '17 at 06:32
  • you have not installed any packages yet, try npm install express --save and you will see express inside your node_modules – sac Dahal Jan 10 '17 at 06:38

1 Answers1

3

When you do npm init you might have entered the values like the below in CLI:

name: (testApp) 
Sorry, name can no longer contain capital letters.
name: (testApp) testApp
Sorry, name can no longer contain capital letters.
name: (testApp) test-app
version: (1.0.0) 
description: This is a test app
entry point: (index.js) app.js
test command: npm test
git repository: 
keywords: 
author: Sagar Gopale
license: (ISC) 
About to write to /home/sagargopale/Projects/testApp/package.json:

Then there is package.json created as follows with the above configuration:

{
  "name": "test-app",
  "version": "1.0.0",
  "description": "This is a test app",
  "main": "app.js",
  "scripts": {
    "test": "npm test"
  },
  "author": "Sagar Gopale",
  "license": "ISC"
}

When you install any dependency it will add the dependencies block in package.json. For example if I do

npm install express --save

then the package.json will look like below:

{
  "name": "test-app",
  "version": "1.0.0",
  "description": "This is a test app",
  "main": "app.js",
  "scripts": {
    "test": "npm test"
  },
  "author": "Sagar Gopale",
  "license": "ISC",
  "dependencies": {
    "express": "^4.14.0"
  }
}
XCEPTION
  • 1,671
  • 1
  • 18
  • 38
  • Everyone is talking about using --save when it is supposed to be the [default ][1] [1]: https://stackoverflow.com/questions/19578796/what-is-the-save-option-for-npm-install I did the same as the OP, and then installed a couple modules, but the dependencies node in the package.json is still EMPTY (latest of everything). But magically, everything still works ! Even a Dockerfile referencing this seems to just work within the container. Seems like this node is redundant now and is smart enough to know whats needed from the code and as is their norm they failed to document it? – killjoy Apr 28 '18 at 17:05