Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

urgot

Package Overview
Dependencies
7
Maintainers
1
Versions
31
Issues
File Explorer

Advanced tools

urgot

a Node.js web framework

    0.3.1latest

Version published
Maintainers
1
Yearly downloads
1,596

Weekly downloads

Readme

Source

Language

English | 简体中文

Urgot is a Nodejs HTTP middleware framework written in Typescript. It allows you to create and pass down requests in the middleware, then filter and respond in reverse order. It comes with an out-of-the-box application development framework, hot update, Session, etc. It supports both Javascript and Typescript.

Installation

$ npm install urgot

Hello World

//index.js import { Server } from "urgot" const server = new Server() server.use(async (context, next) => { context.body = "Hello World" await next() }) server.run(8080)

Middleware

Middleware is the main function of urgot. Calling the use method to register a middleware requires an asynchronous function (Promise) as a parameter.

server.use(async (context, next) => { const start = Date.now() await next() const ms = Date.now() - start context.setHeader("X-Response-Time", `${ms}ms`) context.body = "Hello World" })

Tips: Whenever you should call await next() to let the downstream intermediate response execution.

Context and Next functions

Each middleware will receive a Context object and a next asynchronous function. The Context object is the encapsulation of Http.ServerResponse, of course you can visit context.response to access it, but usually we do not recommend it. After processing the middleware, you need to call the next function to let the downstream middleware Respond to execution.

Demo

https://gitee.com/apprat/urgot-server

License

MIT

Keywords

Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc