4

I don't understand how node packages are managed in nodester. When I run nodester npm install <package-name> from CLI I don't see any packages in my app's source folder. Without these packages visible in my folder, can I use them in usual way (as if I had I installed them in my apps folder directly).

I am advised against storing packages directly in the folder since Nodester offers Node PaaS for free and it would be unkind to not optimize my app and make it use minimal space.

Secondly is there a way through which I can run the app both locally and on nodester. How can I tell git not to push the locally installed git modules. I have heard something like git ignore. How do I manage git ignore so that my local packages are not pushed on nodester?

I might not have been eloquent in framing the question as I am a newbie to node so anyone who can put my question in a better way, feel free to Edit this.

Juzer Ali
  • 4,109
  • 3
  • 35
  • 62
  • This really sounds like two separate questions (where does nodester put packages, how can I run the app in both places). It'll probably be easier for people to answer if you edit this to be just one question, and ask the second one separately. – Joe White Mar 29 '12 at 12:56

1 Answers1

2

Generally the best way is to add the node_modules dir to your .gitignore file. My .gitignore looks like this for my node projects:

*.sw*
.DS_Store
node_modules

The first line ignores any Vim temp files, the second to ignore OSX .DS_Store files and the last one ignores my node_modules dir. You will need to delete your node_modules dir from your repo first using git rm if its already committed.

More explination re. gitignore files is here from GitHub.

So that will make Git disregard your node_modules, awesome. Secondly, you will need to create a package.json file. This is what tells npm (and Nodester) what your app depends on.

{
  "author": "Mr Awesome",  // This is your name :)
  "name": "my_awesome_app",  // This is your apps name 
  "description": "More awesome than most other apps.",  // What your app does
  "version" : "0.0.1",  // Your apps version (increment this when you deploy)
  "node": "0.6.12",  // The version of node you want Nodester to run your app on
  "dependencies": {
     "connect" : "2.0.3", // depend on version 2.0.3 of connect 
     "express" : "*" // depend on the latest version of express
  }
}

More information about package.json formats can be found here:

When you push to nodester should read the package.json and install your dependencies.

Hope that helps!

antz29
  • 754
  • 6
  • 10
  • Where will the dependencies be installed? Will there be installed with my app only? Does that mean that mentioning them in `dependencies` and installing them in the folder directly are the same thing? – Juzer Ali Mar 29 '12 at 16:52
  • by "installing them in the folder" do you mean just committing your node_modules dir? this should always be avoided. mentioning them in `dependencies` and using `nodester npm install [module]` are technically the same thing. – antz29 Mar 29 '12 at 18:08
  • They will, you can install them locally, just don't commit them into the repository. use `npm install` run in your working dir to install everything from the package.json file. The .gitignore file ensures they don't get committed. – antz29 Mar 30 '12 at 09:52
  • Just out of curiosity, not that I would ever do that, can I deploy an app on nodester with npm packages installed inside my package. For e.g. I have installed packages using `npm install express` and haven't `.gitignore`d it. Will this app work, can I use express this way? – Juzer Ali Mar 30 '12 at 10:18
  • I don't think this would work (feel free to try) but I don't know the detail of how this works in Nodester. In theory, it *might* work. – antz29 Mar 30 '12 at 12:11
  • I placed `node_modules` in my ignore.gitignore file, but it is still uploading node modules to git. – Juzer Ali Mar 31 '12 at 17:08
  • did you git rm the node_modules dir first? also see the git rm man page https://www.kernel.org/pub/software/scm/git/docs/git-rm.html – antz29 Jan 24 '14 at 14:23