Giter Site home page Giter Site logo

userv's Introduction

UServ

Start developing server apps in seconds

Fast, unopinionated, minimalist server;)

A server based on urout

Features

  • Lightweight - less than 1.7kb min+gzip
  • No Dependency - No Bloating. No external dependencies
  • Express.js Middleware compatible - Middleware support, including Express middleware you already know & love
  • Express.js identical API - Nearly identical application API & route pattern definitions

Install

$ npm install --save userve

Usage

Simple

const userve = require('userve');
const port = 3000;

let app = userve.Server();
let users = userve.Server()
    .get('/', (req, res) => {
        res.end('users!')
    })
app
    .use((req, res, next) => {
        console.log('mid');
        next();
    })
    .use('users', users)
    .get('/', (req, res) => {
        res.end('root /');
    })
    .get('/err', (req, res) => {
        throw 'e';
    })
    .listen(port, () => console.log(`Example app listening on port ${port}!`));

Complex with express middlewares

const userve = require('userve');
const compression = require("compression");
const cors = require('cors');
const path = require('path')
const dir = path.join(__dirname, 'public');
const serve = require('serve-static')(dir);
const morgan = require("morgan");
const helmet = require("helmet");
const multer = require('multer');
const upload = multer({ dest: 'uploads/' })

let birds = userve.Server()
    .get('/', function (req, res) {
        res.end('Birds home page')
    })
    .get('/about', function (req, res) {
        res.end('About birds')
    })

function one(req, res, next) {
    req.hello = 'world';
    next();
}

function two(req, res, next) {
    console.log('two');
    next();
}

userve.Server()
    .use(one, two)
    .use(compression())
    .use(serve)
    .use(cors())
    .use(morgan("common"))
    .use(helmet())
    .use('/birds', birds)
    .get('/', function (req, res) {
        res.setHeader('Content-Type', 'text/plain; charset=utf-8')
        res.end('Hello World!')
    })
    .post('/profile', upload.single('avatar'), function (req, res, next) {
        res.end('Upload Complete!');
    })
    .listen(3000)

API

License

MIT © Kethan Surana

userv's People

Stargazers

 avatar

Watchers

 avatar

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.