The aim of this guide is to get people getting started with Node.js and npm, while also showing some of the handy commands I use to bootstrap my projects.
Create your project directory.
Change to the directory you just created.
Tell git to make a repo.
Pull down a preconfigured
.gitignore file for node projects from github.
wget https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore -O .gitignore
Pull down a basic
Makefile I use for my projects.
This make file contains a few handy targets, these are:
testruns tests in the
testfolder using the mocha test framework.
jshintuses jshint to check over the code.
skelgenerates a basic structure for my project creating
testdirectories and installs mocha and chai the BDD / TDD assertion library.
- The default target which is invoked by just running
make, this runs the
Note: You will need to install jshint globally using
npm install -g jshint.
Now we will use the
skel target to generate our project structure.
Create a project on github using hub, if your on osx you can install this with homebrew. We do this sooner rather than later so npm can pick this information up when building the
Now initialise your project.
This should ask for a bunch of information, note leave the version 0.0.0 we will change this later. For those interested this is driven by init-package-json.
Once you have added some code to
index.js and some tests of course, add and commit your code.
git add . git commit -a 'Initial release'
Now your ready to release use npm to update the version. There are three options for this command being
patch each of which increments the version numbers in that order. In the example below we should go from
npm version minor
Run your tests!
Push to github, the version command automatically tags your project so we can check it out if we need!
git push origin master --tags