Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
@tinyhttp/app
Advanced tools
@tinyhttp/app is a modern, lightweight, and fast web framework for Node.js. It is designed to be a minimalistic alternative to Express.js, providing a similar API but with a smaller footprint and faster performance.
Basic Routing
This code demonstrates how to set up a basic HTTP GET route using @tinyhttp/app. When a GET request is made to the root URL, the server responds with 'Hello, World!'.
const { App } = require('@tinyhttp/app');
const app = new App();
app.get('/', (req, res) => res.send('Hello, World!'));
app.listen(3000, () => console.log('Server is running on http://localhost:3000'));
Middleware Support
This code demonstrates how to use middleware in @tinyhttp/app. The logger middleware logs the HTTP method and URL of each request before passing control to the next middleware or route handler.
const { App } = require('@tinyhttp/app');
const app = new App();
const logger = (req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
};
app.use(logger);
app.get('/', (req, res) => res.send('Hello, World!'));
app.listen(3000, () => console.log('Server is running on http://localhost:3000'));
Error Handling
This code demonstrates how to handle errors in @tinyhttp/app. If an error is thrown in a route handler, the error-handling middleware catches it and sends a 500 Internal Server Error response.
const { App } = require('@tinyhttp/app');
const app = new App();
app.get('/', (req, res) => {
throw new Error('Something went wrong!');
});
app.use((err, req, res, next) => {
res.status(500).send('Internal Server Error');
});
app.listen(3000, () => console.log('Server is running on http://localhost:3000'));
Express is a widely-used web framework for Node.js, known for its robust features and extensive middleware ecosystem. Compared to @tinyhttp/app, Express has a larger community and more plugins, but it is also heavier and may have slower performance.
Koa is a web framework designed by the creators of Express. It uses async functions and promises to provide a more modern and elegant API. Koa is more modular and lightweight than Express, but it requires more boilerplate code compared to @tinyhttp/app.
Fastify is a high-performance web framework for Node.js, designed for speed and low overhead. It offers a schema-based validation system and a powerful plugin architecture. Fastify is similar to @tinyhttp/app in terms of performance but has a different API and feature set.
The core of tinyhttp. Contains the App
, Request
and Response
. Additionally, it provides special tinyhttp-specific types.
pnpm i @tinyhttp/app
import { App } from '@tinyhttp/app'
import type { Request, Response, NextFunction } from '@tinyhttp/app'
new App()
.use((req: Request, res: Response, next: NextFunction) => {
console.log('Did a request')
next()
})
.get('/', (_, res) => res.send('<h1>Hello World</h1>'))
.get('/page/:page', (req, res) => res.send(`You opened ${req.params.page}`))
.listen(3000)
FAQs
0-legacy, tiny & fast web framework as a replacement of Express
The npm package @tinyhttp/app receives a total of 88,499 weekly downloads. As such, @tinyhttp/app popularity was classified as popular.
We found that @tinyhttp/app demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.