A basic node.js app with common libraries installed and explained.
git clone https://github.com/tumblbug/nodejs-basic.git
cd nodejs-basic
npm install
npm run test
Next, you'll probably want to edit package.json to add an author, change the package name and license, etc.
You can do the following to remove this project's README and delete any git history, allowing you to start fresh in a new repository. When creating a new repo for your project to live in, Github will let you know how to add your remote URL.
rm -rf .git README.md
git init
git add remote origin ...
You're now ready to start developing your app!
npm scripts are included as follows:
apprunsindex.jsin the root directorydebugruns app with all debugging enabled, also hides all console log messages to let you focus on debuggingtestruns the test suitetest:watchautomatically re-runs your test suite when code insrcortestdirectories changelintruns ESLint on all of your filescoverageruns Istanbul to produce a test coverage report
ESLint comes pre-installed, extending eslint-config-airbnb. Don't forget to install the appropriate plugin for your editor.
Testing is done using Mocha and Chai.
chai-as-promised is included to test promise-based code.
Mocks, stubs, etc. can be done using Sinon.
Nock is used to test HTTP requests.
Nock also disables your app from performing any HTTP requests during tests (see test/setup.js).
There are examples for each library in test/lib/api-spec.js.
Debugging can be done with the debug library. Initialize it in each of your modules with
const debug = require('debug')('my module name');and then simply use debug instead of console.log.
Add a DEBUG=* flag to debug all modules (same as npm run debug), or you can list certain modules that should be debugged, e.g. DEBUG=api npm run app.
Logging is done using bunyan. See index.js for examples.
Istanbul is used to produce a test coverage report. Look inside the coverage folder after running npm run coverage to see the results.