Git Product home page Git Product logo

douh's Introduction

Node.js Server Framework douh

Introduction

douh is node.js server framework. super slow and heavy. but want to be fast and light. Contributions are always welcome!


Installation

$ npm install douh

Usage

Hello world

when return, douh will send response body.

import App from 'douh';

const app = new App();

app.use(() => {
  return 'hello world!';
});

app.listen(3000);

Middleware

douh supports async middleware.

app.use(async (req, res, next) => {
  console.time('start');
  await next();
  console.timeEnd('end');
});

Use Router

import App, { Router } from 'douh';

const app = new App();
const router = new Router();

router.get('/ping', (req, res, next) => {
  return 'pong';
});

app.use(router.middleware());

app.listen(3000);

bodyParser

you can use bodyParser middleware.

import App, { bodyParser, Router } from 'douh';

const app = new App();
const router = new Router();

router.post('/ping', (req, res, next) => {
  console.log(req.body);
  console.log(req.files); // when content type is multipart/form-data
  return 'pong';
});

app.use(bodyParser);
app.use(router.middleware());

app.listen(3000);

Use Service

you can use service with @Service decorator. access service with req.service.

import App, { Service } from 'douh';

@Service()
class DouhService {
  public hello(name: string) {
    return `hello ${name}`;
  }
}

const app = new App();
app.use(async (req, res) => {
  const result = req.service.userService.hello('douh');
  return result; // hello douh
});

Use Repository

you can use repository with @Repository decorator. access repository in service constructor.

@Repository()
class DouhRepository {
  hello(name) {
    return `hello ${name}`;
  }
}

@Service()
class DouhService {
  constructor(private readonly douhRepository: DouhRepository) {}

  hello(name: string) {
    return this.douhRepository.hello(name);
  }
}

const app = new App();
app.use(async (req, res) => {
  const result = req.service.douhService.hello('douh');
  return result; // hello douh
});

Use File Service

you can use file service with middleware.

import App, { serveStatic } from 'douh';

const app = new App();

app.use(serveStatic('public')); // it must be placed before bodyParser
app.use(bodyParser);

app.listen(3000);

douh's People

Contributors

actav-n avatar changchanghwang avatar dependabot[bot] avatar sm9657 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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.