# nodejs-api-boilerplate

> A NodeJS server boilerplate for help you kickstart you futur node project. ES6/ES7 features.

Latest version **1.0.0** (published 2017-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install nodejs-api-boilerplate
pnpm add nodejs-api-boilerplate
yarn add nodejs-api-boilerplate
bun add nodejs-api-boilerplate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-05-03 |
| First published | 2017-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.10 |
| Dependencies | 24 |
| Known vulnerabilities | 0 (+13 in 5 direct dependencies) |
| Install scripts | no |
| GitHub stars | 466 |
| Author | Emanuel Quimper |
| Maintainers | equimper |
| Keywords | express, es6, es7, rest, api, boilerplate, mongo, node, javascript, pm2, babel, nps, commitizen, semantic-release, prettier, lint-staged |

## Links

- npm: https://www.npmjs.com/package/nodejs-api-boilerplate
- Repository: https://github.com/EQuimper/nodejs-api-boilerplate
- Homepage: https://github.com/EQuimper/nodejs-api-boilerplate#readme
- Issues: https://github.com/EQuimper/nodejs-api-boilerplate/issues
- npm.io page: https://npm.io/package/nodejs-api-boilerplate

## Dependencies (24)

- [joi](https://npm.io/package/joi.md) ^10.4.1
- [pm2](https://npm.io/package/pm2.md) ^2.4.6
- [cors](https://npm.io/package/cors.md) ^2.8.3
- [slug](https://npm.io/package/slug.md) ^0.9.1
- [raven](https://npm.io/package/raven.md) ^1.2.1
- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [helmet](https://npm.io/package/helmet.md) ^3.5.0
- [express](https://npm.io/package/express.md) ^4.15.2
- [winston](https://npm.io/package/winston.md) ^2.3.1
- [mongoose](https://npm.io/package/mongoose.md) ^4.9.7
- [passport](https://npm.io/package/passport.md) ^0.3.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.17.1
- [compression](https://npm.io/package/compression.md) ^1.6.2
- [http-status](https://npm.io/package/http-status.md) ^1.0.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^7.4.0
- [passport-jwt](https://npm.io/package/passport-jwt.md) ^2.2.1
- [pretty-error](https://npm.io/package/pretty-error.md) ^2.1.0
- [bcrypt-nodejs](https://npm.io/package/bcrypt-nodejs.md) ^0.0.3
- [passport-local](https://npm.io/package/passport-local.md) ^1.0.0
- [express-winston](https://npm.io/package/express-winston.md) ^2.4.0
- [method-override](https://npm.io/package/method-override.md) ^2.3.8
- [express-validation](https://npm.io/package/express-validation.md) ^1.0.2
- [express-status-monitor](https://npm.io/package/express-status-monitor.md) ^0.1.9
- [mongoose-unique-validator](https://npm.io/package/mongoose-unique-validator.md) ^1.0.5

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-05-03
- 0.1.1 — 2017-04-28
- 0.1.0 — 2017-04-28

## README

[![Code Climate](https://img.shields.io/codeclimate/github/EQuimper/nodejs-api-boilerplate.svg?style=flat-square)](https://codeclimate.com/github/EQuimper/nodejs-api-boilerplate)
[![Coverage Status](https://img.shields.io/coveralls/EQuimper/nodejs-api-boilerplate/master.svg?style=flat-square)](https://coveralls.io/github/EQuimper/nodejs-api-boilerplate?branch=master)
[![Build Status](https://img.shields.io/travis/EQuimper/nodejs-api-boilerplate/master.svg?style=flat-square)](https://travis-ci.org/EQuimper/nodejs-api-boilerplate)
[![CircleCI](https://circleci.com/gh/EQuimper/nodejs-api-boilerplate.svg?&style=shield)](https://circleci.com/gh/EQuimper/nodejs-api-boilerplate)
[![bitHound Overall Score](https://www.bithound.io/github/EQuimper/nodejs-api-boilerplate/badges/score.svg)](https://www.bithound.io/github/EQuimper/nodejs-api-boilerplate)
[![Greenkeeper badge](https://badges.greenkeeper.io/EQuimper/nodejs-api-boilerplate.svg)](https://greenkeeper.io/)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![MIT License](https://img.shields.io/npm/l/stack-overflow-copy-paste.svg?style=flat-square)](http://opensource.org/licenses/MIT)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
[![Dependency Status](https://dependencyci.com/github/EQuimper/nodejs-api-boilerplate/badge)](https://dependencyci.com/github/EQuimper/nodejs-api-boilerplate)
[![dependencies Status](https://david-dm.org/equimper/nodejs-api-boilerplate/status.svg?style=flat-square)](https://david-dm.org/equimper/nodejs-api-boilerplate)
[![devDependencies Status](https://david-dm.org/equimper/nodejs-api-boilerplate/dev-status.svg?style=flat-square)](https://david-dm.org/equimper/nodejs-api-boilerplate?type=dev)
[![nps](https://img.shields.io/badge/scripts%20run%20with-nps-blue.svg?style=flat-square)](https://github.com/kentcdodds/nps)

# NodeJS-API-Boilerplate

[![forthebadge](http://forthebadge.com/images/badges/built-by-developers.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/powered-by-water.svg)](http://forthebadge.com)
[![forthebadge](http://forthebadge.com/images/badges/powered-by-netflix.svg)](http://forthebadge.com)

# Get Started

- [Api Doc](https://github.com/EQuimper/nodejs-api-boilerplate#api-doc)
- [Pre-Commit Hook](https://github.com/EQuimper/nodejs-api-boilerplate#pre-commit-hook)
- [Usage](https://github.com/EQuimper/nodejs-api-boilerplate#usage)
- [Scripts](https://github.com/EQuimper/nodejs-api-boilerplate#scripts)
- [Dev-Debug](https://github.com/EQuimper/nodejs-api-boilerplate#dev-debug)
- [Why toJSON() on methods model](https://github.com/EQuimper/nodejs-api-boilerplate#why-tojson-on-methods-model-)
- [For validation on request](https://github.com/EQuimper/nodejs-api-boilerplate#for-validation-on-request)
- [Seeds](https://github.com/EQuimper/nodejs-api-boilerplate#seeds)
- [Docker](https://github.com/EQuimper/nodejs-api-boilerplate#docker)
- [Techs](https://github.com/EQuimper/nodejs-api-boilerplate#techs)
- [Todos](https://github.com/EQuimper/nodejs-api-boilerplate#add)

## Api Doc

Api doc his hosted on surge. [Link](http://equimper-nodejs-api-boilerplate.surge.sh/)

## Pre-Commit Hook

I've add `pre-commit` and `lint-staged` for lint your code before commit. That can maybe take time :bowtie:

## Usage

For get raven log create account here: [Sentry](https://sentry.io/)

1. Clone the project `git clone https://github.com/EQuimper/nodejs-api-boilerplate.git`.
2. Install dependencies `yarn install` or `npm i`
3. Create a `.env` file in the root like
  ```
  MONGO_URL=yourmongodb
  JWT_SECRET=yoursecret
  RAVEN_ID=yourapikey
  DOCS_WEBSITE=yourwebsite.surge.sh/
  ```

---

## Scripts

### DEV

First thing you want to start babel to compile the project by doing `yarn dev:watch` or `npm run dev:watch`

After

```
yarn dev
```

or

```
npm run dev
```

### DEV-DEBUG

```
yarn dev:debug
```

or

```
npm run dev:debug
```

---

## Why toJSON on methods model ?

`toJSON()` help us to get only the data we want when we push the info to the client. So now we just need to put the user object in the `res.json(user)` and we received only what we want. Why `toAuthJSON()` ? Cause if we populated the post we get the `toJSON()` so the `toAuthJSON()` is the on to call on signup and login for get the token and _id.

```js
toAuthJSON() {
  return {
    _id: this._id,
    token: `JWT ${this.createToken()}`,
  };
},

toJSON() {
  return {
    _id: this._id,
    username: this.username,
  };
},
```

---

## For Validation on Request

I'm using Joi in this boilerplate, that make the validation really easy.

```js
export const validation = {
  create: {
    body: {
      email: Joi.string().email().required(),
      password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/).required(),
      username: Joi.string().min(3).max(20).required(),
    },
  },
};

routes.post(
  '/signup',
  validate(UserController.validation.create),
  UserController.create,
);
```

## Seeds

For seed just run one of this following comand. This is helpful in dev for making fake user.

**This is only available in dev environment**

*You can change the number of seed by changing the number in each script inside `/scripts/seeds`*

- Seeds 10 user `yarn db:seeds-user`
- Clear user collection `yarn db:seeds-clear-user`
- Clear all collection `yarn db:seeds-clear`

---

Monitoring Server on `http://localhost:3000/status`

---


## Docker

```
bash scripts/development.sh
```

---

## Techs

- [Helmet](https://github.com/helmetjs/helmet)
- [Cors](https://github.com/expressjs/cors)
- [Body-Parser](https://github.com/expressjs/body-parser)
- [Morgan](https://github.com/expressjs/morgan)
- [PassportJS](https://github.com/jaredhanson/passport)
- [Passport-Local](https://github.com/jaredhanson/passport-local)
- [Passport-JWT](https://github.com/themikenicholson/passport-jwt)
- [Raven](https://github.com/getsentry/raven-node)
- [Joi](https://github.com/hapijs/joi)
- [Http-Status](https://github.com/adaltas/node-http-status)
- [Lint-Staged](https://github.com/okonet/lint-staged)
- [Pre-Commit](https://github.com/observing/pre-commit)
- [Prettier](https://github.com/prettier/prettier)
- [Eslint Config EQuimper](https://github.com/EQuimper/eslint-config-equimper)
- [Eslint Config Prettier](https://github.com/prettier/eslint-config-prettier)
- [CodeClimate](https://codeclimate.com/)
- [Coveralls](https://github.com/integrations/coveralls)
- [Travis Ci](https://travis-ci.org/)
- [Circle Ci](https://circleci.com/)
- [Greenkeeper](https://greenkeeper.io/)
- [Istanbul](https://github.com/gotwarlost/istanbul)
- [Mocha](https://github.com/mochajs/mocha)
- [Chai](https://github.com/chaijs/chai)
- [Supertest](https://github.com/visionmedia/supertest)
- [NPS](https://github.com/kentcdodds/nps)

---

## Todo

### Add

- [ ] Sendgrid or Other Mail supply
- [ ] Add S3 for user image

---
_Source: https://npm.io/package/nodejs-api-boilerplate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
