node-npm-template
v1.0.2
Published
Template for Node.JS NPM package: VSCode launch task, Unit tests, Travis CI and RunKit custom example
Downloads
10
Maintainers
Readme
node-npm-template
Template of Node.JS NPM package: debug in VSCode, test with Mocha, publish to NPM, demo in RunKit and check in Travis CI.
This module is for people who like see working small examples.
Contents of template:
- Node.js module
- Sync and async tests with Mocha framework and Chai assert
- VSCode launch config to debug tests
- NPM package with that module
- Travis CI integration
- RunKit custom example
Setup locally
Perform these steps to make initial setup of your work environment:
- Install the VSCode
- Install the Node.js, it comes with the NPM package manager
- Open module's folder in the VSCode
- Run
npm install
in the root folder to install dependencies - Press
F5
to run unit tests
Node module
You can edit the module itself here: node-npm-template.js.
Also, check my JS backend / frontend example to learn more about Node.JS modules and Mocha tests.
Sync and async tests
Check out tests/unit-tests.js and tests/functional-tests.js files for examples of tests.
VSCode launch config
Mocha invocation is added to .vscode/launch.json so you can debug tests.
NPM package
NPM package is described in the package.json file.
Also notice test
script command, which defines NPM module tests (invoked by Travis).
To publish such module simply run:
npm publish
in the folder with package.json
file (first time you'll be asked to login with npm adduser
command).
You can show nice badge of your NPM package in your README.md file:
Travis CI
To integrate with Travis CI we simply need to add .travis.yml file to the root of GitHub repo and init it on Travis CI site.
You can check results build results: travis-ci.org/anpur/node-npm-template or even add nice badge to your README.md file:
RunKit custom example
NPM is integrated with RunKit service, which allows user to play with your module in the browser. You can find a link Test node-npm-template in your browser on module's NPM page.
You can add custom RunKit example by adding runkitExampleFilename
field to your package.json which point to some file, in this case runkit-example.js.