Skip to content
Lightweight Node.js boilerplate API with Docker support, test coverage and circle.ci support.
JavaScript Shell Dockerfile HTML
Branch: master
Clone or download
Latest commit 34a1fb0 Dec 26, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.semaphore (ci) Dec 26, 2018
client (feat) added nginx client Oct 29, 2018
lib (fix console logs Dec 26, 2018
test fixed purposefully failing test Oct 23, 2018
.dockerignore added bunch of stuff Jan 29, 2018
.eslintignore refactor: new structure - all files in lib folder; added linting scri… Dec 4, 2017
.eslintrc.js (feature) custom error handling: Added HttpError as global var in ser… Dec 16, 2017
.gitignore remove test vars Dec 25, 2018
CONTRIBUTING.md (getting ready for open source contributing) Adding a bunch of files,… Oct 15, 2017
Dockerfile (docker compose config) removed redundant files and added dev deps to… Dec 25, 2018
LICENSE.md (getting ready for open source contributing) Adding a bunch of files,… Oct 15, 2017
Procfile edit Jun 3, 2017
README.md added docker config for swarm Jan 31, 2018
api-deployment.yaml (ci) Dec 8, 2018
api-service.yaml (ci) edit secrets Dec 8, 2018
app.js tweaks for env Oct 23, 2018
build_image_if_not_exists.sh (ci) test build if not exists bash script Dec 21, 2018
client-deployment.yaml (ci) Dec 8, 2018
client-service.yaml (ci) edit secrets Dec 8, 2018
docker-compose.yml (docker compose config) removed redundant files and added dev deps to… Dec 25, 2018
docker-kompose.yml (deploy) Nov 28, 2018
export-image-tag.sh (ci) test staging deploy promotion Nov 14, 2018
generate-node-env.sh (docker compose config) removed redundant files and added dev deps to… Dec 25, 2018
kops.sh (ci) fix deploy Nov 28, 2018
mongo-deployment.yaml (ci) edit secrets Dec 8, 2018
mongo-persistentvolumeclaim.yaml (kompose) added basic setup Nov 15, 2018
mongo-service.yaml (ci) edit secrets Dec 8, 2018
package-lock.json fix vulnerability Nov 27, 2018
package.json fix vulnerability Nov 27, 2018
sample.variables.env refactor: new structure - all files in lib folder; added linting scri… Dec 4, 2017
smoke_test.sh (ci) fixed smoke test Nov 14, 2018
test-integration.js testing builds Oct 22, 2018
test-unit.js testing builds Oct 22, 2018
test.js (fix console logs Dec 26, 2018

README.md

Lightweight Node.js Boilerplate API

This is a lightweight Node.js boilerplate API with Docker support, test coverage and circle.ci support.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Clone to your local machine:

git clone https://github.com/adnanrahic/boilerplate-api.git

Change into the cloned dir:

cd boilerplate-api

Install required modules:

npm install

Natively

Run dev environment:

npm run dev

Run tests:

npm test

Run Istanbul/NYC test coverage report:

npm run integration

Docker

docker swarn init
docker stack deploy -c docker-compose boilerplate

Prerequisites

To get up and running you can either install Docker and run the app in a container, or just run it natively. For Docker you need to install Docker and docker-compose.

To run natively, you need to install MongoDB and Node.js.

Installing

Running natively

  1. Install Node.js
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

sudo apt-get install -y nodejs
  1. Install MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update

sudo apt-get install -y mongodb-org
  1. Run MongoDB
sudo service mongod start

If needed, stop MongoDB with: sudo service mongod stop

Running with Docker

  1. Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get update

sudo apt-get install -y docker-ce
  1. Check if Docker is installed:
sudo systemctl status docker

Should be similar to:

Output
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
     Docs: https://docs.docker.com
 Main PID: 749 (docker)
  1. Install Docker Compose

Choose the appropriate installation for your OS here.

For Linux

sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

If you get the version returned back the installation was successful.

Running the tests

Running the tests is simple. Just run:

npm test

This will start nodemon and run the tests every time you save a file. This includes all the e2e tests and API tests which interact with the DB.

Integration tests

These tests run against a test db which will be cleared before and after the tests are run. For running the integration tests on every push we run:

npm run integration

This command is run by CircleCi.

Deployment

On a VM:

  • See Installation with Docker.

On Heroku:

  • Fork the repo and add it to your Heroku account. The Procfile is set up to run npm start.

Built With

  • Express - Fast, unopinionated, minimalist web framework for Node.js
  • Node.js - JavaScript on the Server
  • MongoDB - Building on the Best of Relational with the Innovations of NoSQL

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Integration testing

We use CircleCi for integration testing. For the versions available, see the their GitHub repo.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

You can’t perform that action at this time.