forked from danielfsousa/express-rest-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
251b6c6
commit 96be0ac
Showing
41 changed files
with
11,366 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
# trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NODE_ENV=development | ||
PORT=3000 | ||
JWT_SECRET=bA2xcjpf8y5aSUFsNB2qN5yymUBSs6es3qHoFpGkec75RCeBb8cpKauGefw5qy4 | ||
JWT_EXPIRATION_MINUTES=15 | ||
MONGO_URI=mongodb://mongodb:27017/express-rest-es2017-boilerplate | ||
MONGO_URI_TESTS=mongodb://mongodb:27017/express-rest-es2017-boilerplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"rules": { | ||
"no-console": 0, | ||
"no-underscore-dangle": 0, | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "next" }], | ||
"no-use-before-define": ["error", { "variables": false }] | ||
}, | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 8 | ||
}, | ||
"extends": [ | ||
"airbnb" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Convert text file line endings to lf | ||
* text=auto | ||
*.js text | ||
# Denote all files that are truly binary and should not be modified. | ||
*.mp4 binary | ||
*.jpg binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
sudo: required | ||
|
||
language: node_js | ||
node_js: '8' | ||
cache: yarn | ||
|
||
git: | ||
depth: 3 | ||
|
||
branches: | ||
only: | ||
- master | ||
|
||
services: | ||
- docker | ||
|
||
env: | ||
- NODE_ENV=test | ||
- PORT=3000 | ||
- JWT_SECRET=bA2xcjpf8y5aSUFsNB2qN5yymUBSs6es3qHoFpGkec75RCeBb8cpKauGefw5qy4 | ||
- JWT_EXPIRATION_MINUTES=15 | ||
- MONGO_URI_TESTS=mongodb://mongodb:27017/express-rest-es2017-boilerplate | ||
|
||
script: | ||
- yarn docker:test | ||
|
||
# deploy: | ||
# - provider: script | ||
# script: yarn deploy | ||
|
||
after_success: yarn coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "nodemon", | ||
"runtimeExecutable": "nodemon", | ||
"runtimeArgs": [ | ||
"--inspect" | ||
], | ||
"program": "${workspaceRoot}/src/index.js", | ||
"restart": true, | ||
"port": 9229, | ||
"protocol": "inspector", | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
], | ||
"compounds": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0.1.0 / 2017-07-17 | ||
================== | ||
|
||
* Initial commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Contributing | ||
|
||
All contributions are welcome! | ||
|
||
- Before spending lots of time on something, ask for feedback on your idea first. | ||
- Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations. | ||
- Fork the repository to your own account | ||
- Clone the repository | ||
- Make changes | ||
- Submit a pull request with tests on develop branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:8-alpine | ||
|
||
EXPOSE 3000 | ||
|
||
ARG NODE_ENV | ||
ENV NODE_ENV $NODE_ENV | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD package.json yarn.lock /app/ | ||
RUN yarn --pure-lockfile | ||
ADD . /app | ||
|
||
CMD ["yarn", "docker:start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,172 @@ | ||
# express-rest-es2017-boilerplate | ||
⌛️ Express boilerplate for building RESTful APIs | ||
# Express ES2017 REST API Boilerplate | ||
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com) [![Build Status](https://travis-ci.org/danielfsousa/express-rest-es2017-boilerplate.svg?branch=master)](https://travis-ci.org/danielfsousa/express-rest-es2017-boilerplate) [![Coverage Status](https://coveralls.io/repos/github/danielfsousa/express-rest-es2017-boilerplate/badge.svg?branch=master)](https://coveralls.io/github/danielfsousa/express-rest-es2017-boilerplate?branch=master) | ||
|
||
Boilerplate/Generator/Starter Project for building RESTful APIs and microservices using Node.js, Express and MongoDB | ||
|
||
## Features | ||
|
||
- No transpilers, just vanilla javascript | ||
- ES2017 latest features like Async/Await | ||
- CORS enabled | ||
- Uses [yarn](https://yarnpkg.com) | ||
- Express + MongoDB ([Mongoose](http://mongoosejs.com/)) | ||
- Consistent coding styles with [editorconfig](http://editorconfig.org) | ||
- [Docker](https://www.docker.com/) support | ||
- Uses [helmet](https://github.com/helmetjs/helmet) to set some HTTP headers for security | ||
- Load environment variables from .env files with [dotenv](https://github.com/rolodato/dotenv-safe) | ||
- Request validation with [joi](https://github.com/hapijs/joi) | ||
- Gzip compression with [compression](https://github.com/expressjs/compression) | ||
- Linting with [eslint](http://eslint.org) | ||
- Tests with [mocha](https://mochajs.org), [chai](http://chaijs.com) and [sinon](http://sinonjs.org) | ||
- Code coverage with [istanbul](https://istanbul.js.org) and [coveralls](https://coveralls.io) | ||
- Git hooks with [husky](https://github.com/typicode/husky) | ||
- Logging with [morgan](https://github.com/expressjs/morgan) and [winston](https://github.com/winstonjs/winston) | ||
- Authentication and Authorization with [passport](http://passportjs.org) | ||
- API documentation geratorion with [apidoc](http://apidocjs.com) | ||
- Continuous integration support with [travisCI](https://travis-ci.org) | ||
- Monitoring with [pm2](https://github.com/Unitech/pm2) | ||
|
||
## Requirements | ||
|
||
- [Node v7.6+](https://nodejs.org/en/download/current/) or [Docker](https://www.docker.com/) | ||
- [Yarn](https://yarnpkg.com/en/docs/install) | ||
|
||
## Getting Started | ||
|
||
Clone the repo and make it yours: | ||
|
||
```bash | ||
git clone xxx | ||
cd xxx | ||
rm -rf .git | ||
``` | ||
|
||
Install dependencies: | ||
|
||
```bash | ||
yarn | ||
``` | ||
|
||
Set environment variables: | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
## Running Locally | ||
|
||
```bash | ||
yarn dev | ||
``` | ||
|
||
## Running in Production | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
## Lint | ||
|
||
```bash | ||
# lint code with ESLint | ||
yarn lint | ||
|
||
# try to fix ESLint errors | ||
yarn lint:fix | ||
|
||
# lint and watch for changes | ||
yarn lint:watch | ||
``` | ||
|
||
## Test | ||
|
||
```bash | ||
# run all tests with Mocha | ||
yarn test | ||
|
||
# run unit tests | ||
yarn test:unit | ||
|
||
# run integration tests | ||
yarn test:integration | ||
|
||
# run all tests and watch for changes | ||
yarn test:watch | ||
|
||
# open nyc test coverage reports | ||
yarn coverage | ||
``` | ||
|
||
## Validate | ||
|
||
```bash | ||
# run lint and tests | ||
yarn validate | ||
``` | ||
|
||
## Logs | ||
|
||
```bash | ||
# show all logs | ||
yarn logs | ||
|
||
# show error logs | ||
yarn logs:error | ||
``` | ||
|
||
## Documentation | ||
|
||
```bash | ||
# generate and open api documentation | ||
yarn docs | ||
``` | ||
|
||
## Docker | ||
|
||
```bash | ||
# run container locally | ||
yarn docker:dev | ||
or | ||
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up | ||
|
||
# run container in production | ||
yarn docker:prod | ||
or | ||
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up | ||
|
||
# run tests | ||
yarn docker:test | ||
or | ||
docker-compose -f docker-compose.yml -f docker-compose.test.yml up | ||
``` | ||
|
||
## Deploy | ||
|
||
Set your server ip: | ||
|
||
```bash | ||
DEPLOY_SERVER=127.0.0.1 | ||
``` | ||
|
||
Replace my Docker username with yours: | ||
|
||
```bash | ||
nano deploy.sh | ||
``` | ||
|
||
Run deploy script: | ||
|
||
```bash | ||
yarn deploy | ||
or | ||
./deploy.sh | ||
``` | ||
|
||
## Inspirations | ||
|
||
- [KunalKapadia/express-mongoose-es6-rest-api](https://github.com/KunalKapadia/express-mongoose-es6-rest-api) | ||
- [diegohaz/rest](https://github.com/diegohaz/rest) | ||
|
||
## License | ||
|
||
[MIT License](README.md) - [Daniel Sousa](https://github.com/danielfsousa) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
docker build -t danielfsousa/express-rest-es2017-boilerplate . | ||
docker push danielfsousa/express-rest-es2017-boilerplate | ||
|
||
ssh deploy@$DEPLOY_SERVER << EOF | ||
docker pull danielfsousa/express-rest-es2017-boilerplate | ||
docker stop api-boilerplate || true | ||
docker rm api-boilerplate || true | ||
docker rmi danielfsousa/express-rest-es2017-boilerplate:current || true | ||
docker tag danielfsousa/express-rest-es2017-boilerplate:latest danielfsousa/express-rest-es2017-boilerplate:current | ||
docker run -d --restart always --name api-boilerplate -p 3000:3000 danielfsousa/express-rest-es2017-boilerplate:current | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: "2" | ||
services: | ||
boilerplate-api: | ||
command: yarn dev -- -L |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: "2" | ||
services: | ||
boilerplate-api: | ||
command: yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version: "2" | ||
services: | ||
boilerplate-api: | ||
command: yarn test |
Oops, something went wrong.