1

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?

Kevin
  • 403
  • 1
  • 8
  • 16
  • node_modules and package.json should remain in root and installing packages with the --save flag saves them to your package.json file – baao Oct 06 '15 at 22:28
  • Just to clarify, are you saying there is no way to move node_modules and package.json? Or just that the recommended way is to keep them in root? – Kevin Oct 07 '15 at 02:03
  • 2
    I like having my Node.js code in a sub-directory called `src` (with the `node_modules` folder and `package.json` in that directory). That way I can have build files, dockerfile, .jshintrc, .gitignore, etc. in the root directory while keeping my Node.js "clean" in its own folder. However I haven't figured out how to tell WebStorm how my project is structured. – Nepoxx Nov 13 '15 at 19:31

1 Answers1

1

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.

Community
  • 1
  • 1
xaviert
  • 5,653
  • 6
  • 29
  • 31
  • 1
    Thanks @xaviert for your answer and sorry for my delayed response. It is not so much that I want to hide node_modules, I still like to get into it from time to time. Rather I have organized my project into a feature-by-feature folder organization, with "client" and "server" sub-folders as the next level folders under each feature name. So I thought it would be consistent to move my bower and node_modules folders to live underneat a /lib top-level directory. But I can't figure out how to do that, at least in my JetBrains IDE. – Kevin Nov 03 '15 at 22:48