1.0.0 • Published 3 years ago

lxu v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

lxu (I am afraid this is not a usefule package)

A web framework based on nodejs. @version 0.0.5 Basic core feature is done.

Philosophy

  • Provides super core middlerware handling and static file service and basicly nothing else
  • Asynchronous programming support with 'express' like api

Feature

  • Focuse on middleware handling ✔
  • Async/await ✔
  • As a middlerware for other nodejs web framework such as express ✔
  • Generator simulate async/await (support but not recommend) ✔

Drawback

  • Still in initial phase, for now you may only use it in some non-serious situation
  • For now lxu doesn't accept pull requests

Usage

  • install : npm install lxu
  • require : node v7.6.0 or higher for async function support
  • examples :

    • Start a super simple http server
      //Start a super simple http server
      let lxu = require('lxu');
      let app = lxu();
      app.use((req, res, next)=>{
        res.end('Hello there.');
      });
      app.listen(3000, ()=>{console.log('Listening on 3000...')});
    • Start a http server with static file serve
      //Start a http server with static file serve
      let lxu = require('lxu');
      let app = lxu();
      app.use(lxu.static('./static_file_dir'));
      let server = app.listen(3001, ()=>{console.log(`Listening on ${server.address().port}...`);});
    • Use async middlware
      //Use async middlware
      let lxu = require('lxu');
      let app = lxu();
      app.use('POST', '/some/path', async function(req, res, next){
        // do some stuff...
        let otherServiceResult = await requestOtherService('some_data');
        req.write(otherServiceResult);
        next();
      });
      app.use(async function(req, res, next){
        res.write('End of response.\n');
        res.end();
      });
      app.listen(3002);
    • Use generator simulate async Link for generator simulate async
      //Use generator simulate async
      let lxu = require('lxu');
      let app = lxu();
      app.use(function* (req, res, next){
        let laterVal = yield later();
        res.write(laterVal);
        next();
      });
      app.use(function(req, res, next){
        res.write('End of response.\n');
        res.end();
        next();
      });
      app.listen(3003);
    • As a middleware for other nodejs web framework

      //As a middleware for other nodejs web framework
      let express = require('express');
      let lxu = require('lxu');
      let app = lxu();
      app.use((req, res, next)=>{
        res.write('Hello there.\n');
        next();
      });
      let expressApp = express();
      expressApp.use(app);
      expressApp.use((req, res, next)=>{
        res.end('After lxu middlewares.\n');
        next();
      });
      let server = expressApp.listen(3004, ()=>{console.log(`Listening on ${server.address().port}...`)});
1.0.0

3 years ago

0.0.6

6 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago