New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nodetomic-api-swagger

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodetomic-api-swagger

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

  • 2.8.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Nodetomic-api-swagger

Codacy Badge NPM version Build Status dependencies Status devDependencies Status Gitter chat GitHub license Downloads

Simple and fast Restful API designed for horizontal scalability including cluster, based on Swagger, Socket.io, Nodejs, Redis + Passport, MongoDB, Express

Horizontal scalability
Preview

Swagger Api

http://localhost:8000/docs

Technologies

Codacy

Requirements

  • Nodejs >= 6.x.x (Recommended 8.x.x)
  • MongoDB >= 3.x.x
  • Redis >= 3.x.x (Recommended 4.x.x)

Installation

git clone https://github.com/kevoj/nodetomic-api-swagger
cd nodetomic-api-swagger
npm i

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;

// Constructor
export default (_socket, _io) => {
    socket = _socket;
    io = _io;
    on();
}

// Here should be all events 'on'
export function on() {
  // Listen 'example'
    socket.on('example', function (data) {
  // Emit to cool
      emit('cool', data);
    });
}

// Emit events
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!');

}

Development

Start

npm start

Imgur

Build

npm run build

Imgur

  • Generate output folder: dist

Folder "client" is optional. You can paste the compilation of a client here, for example of Vue, React, Angular ...

Imgur

Test

npm test

Imgur

Lint

npm run lint

Pm2 [Development]

Simple

Run pm2 in a single thread and run pm2 console

npm run dev-simple

Imgur

Cluster

Run pm2 in multiple threads and run pm2 console

npm run dev-cluster

Imgur

Pm2 [Production]

Simple

Run pm2 in a single thread

npm run simple

Imgur

Cluster

Run pm2 in multiple threads

npm run cluster

Imgur

Stop

PM2

destroy pm2 simple and pm2 cluster

npm stop

Node

destroyed all process for node

killall node

License

MIT © Leonardo Rico

Keywords

FAQs

Package last updated on 15 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc