@kos-ng-it-konsult/validator
Validator package for KOS NG IT Konsult
Last updated 10 months ago by oluwaseun.olusi .
ISC · Repository · Original npm · Tarball · package.json
$ cnpm install @kos-ng-it-konsult/validator 
SYNC missed versions from official npm registry.

@kos-ng-it-konsult/validator

This is a joi validation package for KOS NG IT Konsult.

Quick Start

Install

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

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 lib = require('../index');
const validations = require('./validations');
const validator = new lib(validations, console);

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(validator.validateRequest(), endRequest())
    .post(validator.validateRequest(), endRequest());

app.route('/test/:user_id')
    .get(validator.validateRequest(), endRequest())
    .put(validator.validateRequest(), endRequest());

const server = http.Server(app);

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

Current Tags

  • 0.0.3                                ...           latest (10 months ago)

3 Versions

  • 0.0.3                                ...           10 months ago
  • 0.0.2                                ...           10 months ago
  • 0.0.1                                ...           10 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 3
Last Month 3
Dependencies (3)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |