0.0.3 • Published 5 years ago

@kos-ng-it-konsult/socket v0.0.3

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
5 years ago

@kos-ng-it-konsult/socket

This is a socket package for KOS NG IT Konsult.

Quick Start

Install

$ npm i --save @kos-ng-it-konsult/socket

Basic Usage

"use strict";

const express = require('express'); // run npm install --save express
const bodyparser = require('body-parser'); // run npm install --save body-parser
const http = require('http');
const socket = require('@kos-ng-it-konsult/socket');

const app = express();

app.use(bodyparser.urlencoded({ extended: true, limit: '100mb' }));
app.use(bodyparser.json({ limit: '100mb' }));

function endRequest () {
    return (request, response, next) => {
        return response.status(200).send({
            status: 'success',
            message: 'thank you'
        });
    };
}

app.route('/test')
    .get(endRequest())
    .post(endRequest()); // Authenticate user and then authorize user action

app.route('/test/:user_id')
    .get(endRequest()); // Set strict authentication to false

const server = http.Server(app);

socket.connect(server);

server.listen((process.env.PORT || 3005), (error) => {
    if (!error) {
        console.log(`server is listening on port ${ (process.env.PORT || 3005) }`);
    } else {
        console.log(`Error starting server: ${ error.toString() }`);
    }
});

app.use((error, request, response, next) => {
    response.status((error.statusCode || 500)).send({
        status: 'error',
        message: (error.message || 'Internal server error, please try again')
    });
});

Running the Example

To run the example, first install express and body-parser using\ $ npm install --save express\ $ npm install --save body-parser\

Then run the sample command\ $ node ./example/sample.js

Running Tests

Run\ $ npm test

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

6 years ago