Nodetomic Api Swagger

RESTful API Nodejs designed for horizontal scalability, based on Swagger, Redis, JWT, Passport, Socket.io, Express, MongoDB. Support multiple cluster
Include libs

Horizontal scalability

Preview

Swagger Api
http://localhost:8000/docs
Technologies

Requirements
Installation
git clone https://github.com/kevoj/nodetomic-api-swagger
cd nodetomic-api-swagger
npm i
Development
Start
npm start

Optional: npm run modemon
if you want work with nodemon.
Build
npm run build

Generate folder dist
. So "dist/client" is optional. You can paste the compilation of a client here, for example of Vue, React, Angular ...

Test
npm test

Lint
npm run lint
Pm2 [Development]
Simple
Run pm2 in a single thread and run pm2 console
npm run dev-simple

Cluster
Run pm2 in multiple threads and run pm2 console
npm run dev-cluster

Pm2 [Production]
Simple
Run pm2 in a single thread
npm run simple

Cluster
Run pm2 in multiple threads
npm run cluster

Stop
PM2
destroy pm2 simple and pm2 cluster
npm stop
Node
destroyed all process for node
killall node
How to create..
Model
src/api/models/hello.js
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const HelloSchema = new Schema({
greet: {
type: String,
required: [true, 'Greet is required.']
},
language: {
type: String,
required: [true, 'Language is required.']
}
});
export default mongoose.model('Hello', HelloSchema);
Controller
src/api/controllers/hello.js
import { result, notFound, error } from 'express-easy-helper';
import Hello from '../models/hello';
export function list(req, res) {
return Hello.find().exec()
.then(notFound(res))
.then(result(res))
.catch(error(res));
}
Swagger (Router)
src/api/swagger/hello.yaml
/api/hello:
x-swagger-router-controller: hello
get:
operationId: list
tags:
- Hello
summary: Get list Hello's
description: Returns all hello
responses:
200:
description: Success
404:
description: Not found
500:
description: Error
Swagger (Router + middleware)
src/api/swagger/hello.yaml
/api/hello:
x-swagger-router-controller: hello
get:
operationId: list
security:
- Bearer: []
x-security-scopes:
- admin
tags:
- Hello
summary: Get list Hello's
description: Returns all hello
responses:
200:
description: Success
404:
description: Not found
500:
description: Error
Socket
src/api/sockets/hello.js
export let socket = null;
export let io = null;
export default (_socket, _io) => {
socket = _socket;
io = _io;
on();
}
export function on() {
socket.on('example', function (data) {
emit('cool', data);
});
}
export function emit(event, data) {
io.emit(event, data);
}
Controller + Socket
src/api/controllers/hello.js
import { result } from 'express-easy-helper';
import { emit } from '../sockets/hello';
export function test(req, res) {
emit('hello','world');
return result(res, 'Socket emitted!');
}
License
MIT © Leonardo Rico