Skeleton api using expressjs.
Note:
This skeleton only for api development, and using es2015 features.
How to use this skeleton?
It's easy to use it. Initializing your project by clone this repo, example:
git clone https://github.com/hiraqdev/base-express my-project
Dont forget to change values:
package.json
- create
.env
fromenv.sample
NodeJS: 8.11.1
ExpressJS: 4.16.3
Coding standard: standardjs
REST standard: jsonapi
Database: MongoDB
ODM: Mongoose
Test: Jest
Default middlewares:
- body-parser
- helmet
- morgan
yarn run build
: Build using babelyarn run api
: Build and run apiyarn run standard
: Run standardjs checkeryarn run summary
: Run standardjs checker with standard-summaryyarn run test
: Run jestyarn run compose
: Run docker-compose engine
build:
docker build -t <your_image_name> .
running a container:
docker run --name base-express-api -e MONGO_URI=<mongo_uri> -p 3000:3000 -d <your_image_name>
running docker-compose:
yarn compose
I'm using dotenv
rules, all available configurations placed at env.sample
.
You need to copy this file to .env
and change all values.
NOTE:
-----
This file (`.env`) will used as configuration for `docker-compose.yml` too.
I'm using pm2-runtime
only for container based, please check Dockerfile
. When
running this engine without docker (yarn run api
), i'm just using node app.js
.
Change MONGO_URI
value in your .env
file and setup based on your actual mongo instance.
For more information: Mongoose Connection
Command:
yarn test
Example output:
$ yarn test
yarn run v1.12.3
$ jest
PASS tests/helpers/jsonapi.test.js
test helpers/jsonapi - function: data
✓ jsonapi data structure success (7ms)
✓ jsonapi data structure adding rest payload (1ms)
test helpers/jsonapi - function: error
✓ jsonapi error structure success (1ms)
✓ jsonapi error structure adding code (1ms)
test helpers/jsonapi - function: errors
✓ jsonapi errors structure success (1ms)
✓ jsonapi errors structure return empty object
PASS tests/test.test.js
✓ test simple sum (1ms)
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
jsonapi.js | 100 | 100 | 100 | 100 | |
------------|----------|----------|----------|----------|-------------------|
Test Suites: 2 passed, 2 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 0.927s, estimated 1s
Ran all test suites.
Done in 1.86s.