8

I have a project in which I use node-webkit. node-webkit allows npm packages to be used for developing desktop applications. I make use of grunt to build my application.

My folder structure looks like this at the moment:

project root
    node_modules/ (1)
    package.json  (1)
    App/
        node_modules/ (2)
        package.json  (2)
        bower.json
        bower_components/
        ... 
        controllers/
        filters/
        ...
        app.js

The npm dependencies for the application itself are kept within the App folder, but the dev dependencies for building the project are not related to the application source code, so i keep them in node_modules (1) inside the root folder. I also know that in a package.json file one can express dependencies and dev dependencies, exactly for this reason. I would rather have one package.json file in the root expressing ALL dependencies, including dev dependencies, but i would rather have a separation of those dependencies on folder level.

Two questions arise:

  1. Is this a good way to organize my npm dependencies? If yes, awesome? If no, which I expect:

  2. What is a better way to organize my dependencies? Is it possible to specify that dev dependencies go into folder a, and 'regular' dependencies go into folder b? If so, how do I do this?

In case anyone is wondering, this is the project i am talking about:

https://github.com/michahell/pinbored-webkit

[updated folder structure to include app.js for clarity]

Michahell
  • 4,905
  • 5
  • 29
  • 45
  • Why thank you for editing my question so quickly @marc_s! – Michahell Sep 18 '14 at 14:34
  • Most of the work was handled by @mscdex - he got the `dependency` (instead of `dependancy`) fixed before I could... – marc_s Sep 18 '14 at 14:35
  • I *&%$ allways write that (and some other things) wrong. Will watch out for it :) – Michahell Sep 19 '14 at 03:46
  • @Michael Did you find a solution yet? I'd like to use the same structure as you do, with dev dependencies outside, and app dependencies inside the App folder, but I'm hesitant to split up my `package.json` – Jorn Nov 24 '15 at 16:25
  • 1
    Hello @Jorn, well no I haven't and I maintain 2 package.json files.. I think I have a script in the (main/dev) package.json that does a cd App && npm install, so you only have to perform npm install once. I still don't like it though... let me know if you find a better solution! – Michahell Nov 25 '15 at 09:54
  • I'm doing the exact same thing now. It works, but meh... – Jorn Nov 25 '15 at 11:44

2 Answers2

1

It is perfectly fine to keep more than one package.json file and multiple node_module directories for a project. If you consider the parts as separate components.

An example might be if, you have one directory containing a node server, another containing a react app, and a third containing some kind of deployment script written in javascript.

Justin Ohms
  • 3,334
  • 31
  • 45
-6

@Michael package.json file contains all the dependencies related to that project.There is no need for multiple package files and multiple node_modules folders.. But you need to check where is your App.js file!! your App.js , package.json must be in same folder unless configured.

Anirudh Negi
  • 169
  • 13
  • Thanks, @anirudh, i've updated my question according to your answer. My app.js is inside the /App folder and i'd like to keep it that way, all application specific stuff is inside my /App folder! – Michahell Sep 24 '14 at 15:23
  • @Michael i think you do not need outer package.json and outer node_module folder now!! :) – Anirudh Negi Sep 25 '14 at 06:53
  • i do need that because i am building my node-webkit app with Grunt, and grunt needs npm dependancies (dev dependancies in my case). – Michahell Oct 01 '14 at 13:24