Quick boilerplate code to get started with nodeJS, Sequelize, MochaJS, IstanbulJS, passport-bearer.
Note: This app uses postgres database with Sequelize ORM. So install, start postgres and edit the config file as below
simpleApp > server > config > config.json
Sample
{
"development": {
"username": "postgres",
"password": "loremIpsum",
"database": "simpleapp",
"host": "localhost",
"port": "5432",
"dialect": "postgres",
"maxIdleTime": 30
},
}
Install the dependencies and start the server.
$ cd simpleApp
$ npm install
$ npm start:dev
- Signin
- Save token
- Get token
- Querystring
POST /api/signin
- username: string
- password: string
OK
Unauthorized
POST /api/token
- token_id: string
{
"id": 2,
"token_id": "secretKitty",
"updatedAt": "2017-10-11T04:32:01.947Z",
"createdAt": "2017-10-11T04:32:01.947Z"
}
Note: The following route is api protected. Include token_id in header for authorization
{
Authorization: Bearer <token_id>
}
GET /api/token
Authorized
GET /api/q
- id: string
id
This app uses MochaJS and IstanbulJS for Testing and coverage respectively. To test the API end points,
$ npm run test
You should see something like this if the tests pass
Happy Hacking !