
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@vercel/h3
Advanced tools
@vercel/h3 is a minimalistic HTTP framework for building web applications and APIs. It is designed to be lightweight and fast, making it suitable for serverless environments and edge computing.
Creating a basic HTTP server
This code demonstrates how to create a basic HTTP server using @vercel/h3. The server listens on port 3000 and responds with 'Hello, world!' to any incoming request.
const { createServer } = require('@vercel/h3');
const app = createServer((req, res) => {
res.end('Hello, world!');
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Handling JSON requests and responses
This example shows how to handle JSON requests and send JSON responses using @vercel/h3. The server reads a JSON body from the request, processes it, and sends a JSON response.
const { createServer, json } = require('@vercel/h3');
const app = createServer(async (req, res) => {
const body = await json(req);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ message: 'Hello, ' + body.name }));
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Middleware support
This code demonstrates how to use middleware in @vercel/h3. A simple logger middleware is created and applied to the server, logging each request's method and URL.
const { createServer, use } = require('@vercel/h3');
const logger = (req, res, next) => {
console.log(`${req.method} ${req.url}`);
next();
};
const app = createServer();
use(app, logger);
app.use((req, res) => {
res.end('Hello, world!');
});
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
});
Express is a widely-used web application framework for Node.js, known for its robust features for building web and mobile applications. Compared to @vercel/h3, Express is more feature-rich and has a larger ecosystem, but it may not be as lightweight or optimized for serverless environments.
Koa is a web framework designed by the team behind Express, aiming to be a smaller, more expressive, and more robust foundation for web applications and APIs. Koa uses async functions, providing a cleaner and more modern approach compared to Express. It is similar to @vercel/h3 in its minimalistic design but offers more flexibility with middleware.
Fastify is a web framework focused on providing the best developer experience with the least overhead and a powerful plugin architecture. It is known for its speed and low overhead, making it comparable to @vercel/h3 in terms of performance, but Fastify offers a more extensive plugin system and ecosystem.
FAQs
Unknown package
The npm package @vercel/h3 receives a total of 389,276 weekly downloads. As such, @vercel/h3 popularity was classified as popular.
We found that @vercel/h3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 321 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.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.