Kevin
Kevin

Reputation: 403

PhpStorm / WebStorm node_modules and package.json

Some related questions:

First, I am using PhpStorm 9.0.2 and would like to move the node_modules package directory from the root directory of my project to a sub-directory. But when I try to do this all of the packages I have installed no longer show up in the "Node.js and NPM" settings page. I can't seem to find where to set the path, is this even something that is possible to do?

Second, I notice that my package.json file has a few dependencies in it, perhaps the defaults from when my project was set up. But most of the Node.js packages I've installed since then don't show up. Is there a way in PhpStorm or otherwise to make sure package.json is automatically kept sync'ed with the packages I currently have installed? That is what seems to happen with bower.json and my client-side packages.

Third, I would also like to move package.json to a sub-directory, can I do this somehow?

Upvotes: 1

Views: 1809

Answers (1)

xaviert
xaviert

Reputation: 5942

The node_modules directory is always located right next to the package.json. As long as you move both into the same subdirectory, things might be OK depending on how/where you run the Node.js code from.

Personally though, I don't understand why you would want to move only the node_modules directory. Based on various resources (such as this one) it's recommended to not check-in the node_modules directory. In your IDE you can also exclude this folder so it's no longer shown in the file browser window.

For your last question, when executing npm install xxx, the dependency is not saved into your package.json file. In order to save it, add the --save (or --save-dev for test dependencies) flag at the end of the install statement: npm install xxx --save.

Upvotes: 1

Related Questions