A RESTful API built with Node.js, Babel and MongoDB
This is an improvement over the previous RESTful API I had. The main change is the use of NPM tasks instead of Gulp to compile, run, test, lint, etc. I found that babel and gulp together are extremely slow for development, any file changes triggered the gulp build which took around 15 seconds (even when managing dependencies with npm3). Now with the use of babel-watch
builds are much faster (1 second or 2).
- Clone the repository
- Install dependencies
npm install
- Start MongoDB server: the project comes with a script in
scripts/mongostart.sh
that will pull a MongoDB image from Docker and start it listening in port 27018. It can also be any other MongoDB server running anywhere. Just make sure you change the connection details inconfig/env/local.js
. - Run the API server with
NODE_ENV=local npm start
- Try the API calling the
http://localhost:3000/api/health-check
endpoint.
- Clone the repository
- Run
docker-compose up --build
- Once the containers is built and the images are running you can reach the API on localhost:3000
- Run
npm run compile
. This will generate thedist
directory with all the code transpiled from ES6 to ES5. - Run the transpiled
dist/index.js
withnode
or any other process manager likepm2
.
All tests are in server/tests
and can be run with npm test
.
To run the tests and generate coverage report with istanbul
run npm run coverage
.
To generate the API documentation simply run npm run docs
. This will create the docs
directory with all the documentation
generated through the apidoc module.
There's an npm task for linting as well, this is useful to check before pushing any code. To run the linting task
execute npm run lint
. ESLint configuration can be changed in .eslintrc
.