Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js npm dependencies in subfolder

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]

like image 897
Michael Trouw Avatar asked Sep 18 '14 14:09

Michael Trouw


1 Answers

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.

like image 94
Justin Ohms Avatar answered Sep 18 '22 09:09

Justin Ohms