3

I have developed my first Node.js pp. For now, it just sits on my laptop.

During development I had to install some modules:

npm install socket.io
npm install [email protected]
npm install iniparser
npm install js-yaml
npm install nodemailer

I have installed all of them "per-project", not globally.

The directory of my project looks like this (my code is all in push_server.js):

|
|--- push_server.js
|
|--- node_modules
     |--- iniparser
     |--- js-yaml
     |--- mysql
     |--- socket.io
     |--- nodemailer

Now I want to push this project to the production server.

My question is: can I upload the whole codebase (including installed modules) or should I upload just the code of my app and re-install the modules one-by-one on the server?

Note: my dev machine runs Ubuntu 10.04, the production server runs CentOS 5.3

I think all those modules are made up of js files only, therefore it should be allright.
However, is it possible that a module installed by npm compiles some code on the local machine, therefore that code is likely not to work on another machine. Also, how can I know whether a module does that?

Hope the question is not too silly - I have just started with Node.js.

Thanks.

2 Answers 2

2

You should definitely copy node_modules if possible.

If you re-download them at the server, you run a risk of getting slightly different versions of the modules in use. Even if you require a strict module version X, that module can again have wildcard dependencies to other modules Y Z. This means that if Y is updated and you publish to the server, it will now run using different code for Y than what you used for your local testing and validation.

In some cases you may not even have a required module available at deployment time, because the author has decided to de-publish the package for whatever reason.

4
  • 2
    Those are very good points. But what if a module compile code during its installation - that code is not going to be portable? Is that possible? I guess some of them does.
    – Dan
    Oct 18, 2012 at 13:26
  • 1
    @dan A very good observation. Some modules to that. I'm just used to doing development testing on the same platform as production. In that case you have no choice but to re-install them on production, or introduce a test staging server with the same platform as the production server.
    – Deestan
    Oct 18, 2012 at 13:37
  • Yes, actually I do staging on the same architecture as production...but it is still a pain as I would like the dev machine to run any Linux distribution. How can I tell if some module compiled any software? Unfortunately running "tree" on the "node_modules" directory, I can see some .c and .h files - not good, isn't it?
    – Dan
    Oct 18, 2012 at 13:42
  • 1
    Yes, that looks like it will cause issues. I'd go with a build&test stage server for this, but it really depends on what stability requirements your system has. If it's OK for it to fail sporadically, you don't need to bother much. :)
    – Deestan
    Oct 18, 2012 at 13:51
0

I always try to use the latest versions of the required modules. Node.js is still very young and whenever a module is updated it often brings bugfixes, speed improvements, etc. I install modules locally, test my code on them and finally use them in production. When you install them with npm install module --save they are automatically added to your package.json file as dependencies.

Using git for version control and deployment I usually put the node_modules folder into my .gitignore file. It is therefore not uploaded to my server. On the server you just have to run npm install to install all your required modules, which is much faster than installing them one by one.

This workflow is also used by heroku.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.