![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Cero friction HTTP framework:
const cero = require('0http')
const { router, server } = cero()
router.get('/hello', (req, res) => {
res.end('Hello World!')
})
router.post('/do', (req, res) => {
// ...
res.statusCode = 201
res.end()
})
//...
server.listen(3000)
0http
allows you to define the router implementation you prefer as soon as it support the following interface:
router.lookup = (req, res) // -> should trigger router search and handlers execution
This a 0http
extended implementation of the trouter router. Includes support for middlewares, nested routers and shortcuts for routes registration.
As this is an iterative regular expression matching router, it tends to be slower than find-my-way
when the number of registered routes increases; to mitigate this issue, we use
an internal(optional) LRU cache to store the matching results of the previous requests, resulting on a super-fast matching process.
Supported HTTP verbs: GET, HEAD, PATCH, OPTIONS, CONNECT, DELETE, TRACE, POST, PUT
const cero = require('0http')
const { router, server } = cero({})
// global middleware example
router.use('/', (req, res, next) => {
res.write('Hello ')
next()
})
// route middleware example
const routeMiddleware = (req, res, next) => {
res.write('World')
next()
}
// GET /sayhi route with middleware and handler
router.get('/sayhi', routeMiddleware, (req, res) => {
res.end('!')
})
server.listen(3000)
(req, res) => {
res.statusCode = 404
res.end()
}
1000
(err, req, res) => {
res.statusCode = 500
res.end(err.message)
}
Example passing configuration options:
const sequential = require('0http/lib/router/sequential')
const { router, server } = cero({
router: sequential({
cacheSize: 2000
})
})
You can use async middlewares to await the remaining chain execution. Let's describe with a custom error handler middleware:
router.use('/', async (req, res, next) => {
try {
await next()
} catch (err) {
res.statusCode = 500
res.end(err.message)
}
})
router.get('/sayhi', (req, res) => {
throw new Error('Uuuups!')
})
You can simply use sequential
router intances as nested routers:
const cero = require('../index')
const { router, server } = cero({})
const nested = require('0http/lib/router/sequential')()
nested.get('/url', (req, res, next) => {
res.end(req.url)
})
router.use('/v1', nested)
server.listen(3000)
Super-fast raw HTTP router with no goodies. Internally uses a Radix Tree router that will bring better performance over iterative regular expressions matching.
const cero = require('../index')
const { router, server } = cero({
router: require('find-my-way')()
})
router.on('GET', '/hi', (req, res) => {
res.end('Hello World!')
})
server.listen(3000)
0http
is just a wrapper for the servers and routers implementations you provide.
const cero = require('0http')
const { router, server } = cero({
server: yourCustomServerInstance
})
If no server is provided by configuration, the standard Node.js http.Server implementation is used.
Because this server offers the best balance between Node.js ecosystem compatibility and performance, we highly recommend it for most use cases.
low
is a tiny Node.js friendly wrapper around the great uWebSockets.js HTTP server. I/O throughput is
maximized at the cost of API compatibility.
As far as for Node.js,
uWebSockets.js
brings the best I/O performance in terms of HTTP support.
npm i uNetworking/uWebSockets.js#v15.11.0
const low = require('0http/lib/server/low')
const cero = require('0http')
const { router, server } = cero({
server: low()
})
router.get('/hi', (req, res) => {
res.end('Hello World!')
})
server.listen(3000, (socket) => {
if (socket) {
console.log('HTTP server ready!')
}
})
// ...
server.close()
Node version: v12.14.0
Laptop: MacBook Pro 2019, 2,4 GHz Intel Core i9, 32 GB 2400 MHz DDR4
Server: Single instance
wrk -t8 -c40 -d5s http://127.0.0.1:3000/hi
Requests/sec: 135436.99
Requests/sec: 134281.32
Requests/sec: 88438.69
Requests/sec: 87597.44
Requests/sec: 73455.97
Requests/sec: 85839.17
Requests/sec: 82682.86
For more accurate benchmarks please see:
FAQs
Zero friction HTTP request router. The need for speed!
The npm package 0http receives a total of 4,174 weekly downloads. As such, 0http popularity was classified as popular.
We found that 0http demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.