Coder Social home page Coder Social logo

aaron5670 / expressjs-socketio-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
46.0 3.0 17.0 138 KB

๐Ÿ“ฆ Simple Express.js & Socket.io Boilerplate

JavaScript 100.00%
express express-js socket socket-io socket-server socketio-server boilerplate boilerplate-template boilerplate-node nodejs

expressjs-socketio-boilerplate's Introduction

๐Ÿ“ฆ Express.js & Socket.io Boilerplate

Simple Express.js & Socket.io Boilerplate.

โœจ Features

  • Express 4.16
  • Mongoose 5.7
  • Passport.js with Bcrypt.js
    • Login endpoint
    • Register endpoint
    • Username availability check endpoint
    • Authenticated endpoint
    • Logout endpoint
  • Socket.io integration for real-time, bidirectional and event-based communication.
  • Generates automatically API docs based on Express existing routes with Swagger UI.
  • Social login / register integration.

๐Ÿ“ Getting Started

git clone https://github.com/aaron5670/ExpressJS-SocketIO-Boilerplate.git

cd expressjs-socketio-boilerplate

npm install

// Optional: if you want dummy data, then run this seed file
node seed.js

node server.js

โšก Create Socket.io connection

Install on your client-side (web) application the module socket.io-client.

npm install socket.io-client

Then create a connection with the following code:

// with ES6 import
import io from 'socket.io-client';
 
const socket = io('http://localhost:3005');

For more info you can read the official Socket.io documentation:

๐Ÿ““ How to document the Swagger UI endpoint API

/**
 * @typedef ResponseJSON
 * @property {string} username - user's username - eg: janet
 * @property {string} message - message - eg: This is a authenticated route!
 */
/**
 * Dashboard endpoint only allowed for authenticated users
 * @route GET /api/v1/auth/dashboard
 * @group Auth
 * @returns {ResponseJSON.model} 200
 * @produces application/json
 */
router.get('/dashboard', authenticationMiddleware(), (req, res) => {
    return res.json({
        username: req.session.passport.user.username,
        message: 'This is a authenticated route!'
    });
});

If you are running this boilerplate on you localhost you can see the Swagger UI documentation on: http://localhost:3005/api-docs/.

Note: Check if your port number is the same as your configuration.

๐Ÿ“Œ Swagger UI example

Swagger UI Docs

๐Ÿš€ Endpoints

The following endpoints are available

Login

url:    /api/v1/auth/login
method: POST

This request expects the following body:

{
  "username": "jane", 
  "password": "securepassword1"
}

It will response the client the following object after a successful login:

{
  "success": true,
  "username": "jane",
  "message": "Successful login, welcome!"
}

Register

url:    /api/v1/auth/register
method: POST

This request expects the following body:

{
  "name": "John Doe",
  "username": "john",
  "password": "password123"
}

It will response the client the following object after a successful register:

{
  "success": true,
  "message": "User is successfully registered!"
}

Username availability check

url:             /api/v1/auth/username-availability
method:          GET
query parameter: username

This request expects a request like:

https://localhost:3005/api/v1/auth/username-availability?username=john

It will response the client the following object after a successful request:

{
  "usernameAlreadyInUsage": true
}

Logout

url:    /api/v1/auth/logout
method: GET

It will response the client the following object after a successful request:

{
  "success": true
}

expressjs-socketio-boilerplate's People

Contributors

aaron5670 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

expressjs-socketio-boilerplate's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.