Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best workflow using node.js npm and git

Tags:

git

node.js

npm

I am about to do a large project with node.js and currently try sort a few things out.

In earlier node projects I had an extra folder for all node modules I used. This folder was ignored by git and I managed version and updates via git submodules, which was not easy (no dependencies, updating to new version was not always fun.)

What I am looking for is:

npm install packagename
npm dump_modules_into_file

So everyone else who is involved in this project could do:

npm install_or_update_modules_from_file

I don not want to have node_modules tracked by my git repository. Basically I want something similar to how symonfy2 handles it bundles.

P.S.: I know about npm submodule packagename, but this command is not very helpful because it does not install dependencies and it does not update the modules.

P.S.2: I ready about the package.json, but this also has some flaws. (No parameters and you have to update module versions by hand.)

like image 895
TheHippo Avatar asked Feb 07 '12 23:02

TheHippo


People also ask

How do I use simple Git in Node JS?

A light weight interface for running git commands in any node.js application. Installation – Easiest through npm: npm install simple-git Dependencies – Requires git to be installed and that it can be called using the command git. const simpleGit = require (‘simple-git’) (workingDirPath);

How do I install simple Git on npm?

Installation – Easiest through npm: npm install simple-git Dependencies – Requires git to be installed and that it can be called using the command git. const simpleGit = require (‘simple-git’) (workingDirPath); where the workingDirPath is optional, defaulting to the current directory.

Is Node JS a good choice for web development?

With libraries like browserify, Node.js also begins to blur the line between server-side development and developing for the browser. These reasons, along with many others (such as the vibrant open-source community, driven by npm), make Node.js a great technology choice for the Web.

How to set up a workflow in GitHub?

Once the code is pushed, you can open the GitHub pages and click on “Action”, then click on the “New Workflow” button as in the next image. This will ask what template use, in our case we will choose the node.js one, but this won't exclude do access to all other action available. Now we are ready for setting up the workflow!


1 Answers

package.json will accomplish what you're looking for. In your comment about passing the --mongodb:native flag, that flag is an argument to the npm command and does work when using a package.json in your own project. The mongodb package has an "install script" which looks for that flag in the node processing environment. If that flag is present, then it spawns another process for the build. So, if you have mongodb as a dependency in your package.json

{
    "name": "MyProject"
  , "description": "Test"
  , "version": "0.0.1"
  , "dependencies": {
        "mongodb": "*"
    }
}

Running npm install --mongodb:native will work.

With regards to "updating it by hand" - it's really only the first time that it might take a while, and I'm sure you could write a script to generate it if there are a lot of dependencies. However, it sounds like you have a fairly large team, and if that is the case, then automating the updates to package.json will turn really ugly (think new developers, experimental features, etc.) Having accountability for broken builds in this part of the development cycle isn't necessarily a bad idea.

References:

  • https://github.com/christkv/node-mongodb-native/blob/master/install.js
  • http://package.json.nodejitsu.com/ (see "scripts" section)

EDIT: and as Nick mentioned, adding the 'node_modules' directory to .gitignore will prevent any of those files from being checked into your repo

like image 123
Jesse Fulton Avatar answered Oct 13 '22 06:10

Jesse Fulton