Back to articles
tinyhttp Has a Free Express-Compatible API That Is 2x Faster

tinyhttp Has a Free Express-Compatible API That Is 2x Faster

via Dev.to WebdevAlex Spinov

tinyhttp is a modern, zero-dependency Express alternative that runs 2x faster while keeping the same middleware API. Drop-in replacement for most Express apps. Getting Started npm install @tinyhttp/app import { App } from ' @tinyhttp/app ' ; const app = new App (); app . get ( ' / ' , ( req , res ) => { res . json ({ message : ' Hello from tinyhttp! ' }); }); app . get ( ' /users/:id ' , ( req , res ) => { res . json ({ userId : req . params . id }); }); app . post ( ' /api/data ' , ( req , res ) => { res . status ( 201 ). json ({ received : req . body }); }); app . listen ( 3000 , () => console . log ( ' Running on :3000 ' )); Express Middleware Compatibility Most Express middleware works unchanged: import { App } from ' @tinyhttp/app ' ; import { cors } from ' @tinyhttp/cors ' ; import { logger } from ' @tinyhttp/logger ' ; import { json } from ' milliparsec ' ; const app = new App (); app . use ( cors ()); app . use ( logger ()); app . use ( json ()); Built-in Packages tinyhttp prov

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles