Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More ā†’
Socket
Sign inDemoInstall
Socket

h3

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3

Tiny JavaScript Server

  • 1.8.0-rc.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2M
decreased by-4.18%
Maintainers
1
Weekly downloads
Ā 
Created

What is h3?

The h3 npm package is a high-performance HTTP framework for Node.js, designed to be lightweight and fast. It is often used for building APIs and microservices, providing a simple and efficient way to handle HTTP requests and responses.

What are h3's main functionalities?

Basic HTTP Server

This code demonstrates how to create a basic HTTP server using the h3 package. The server listens on port 3000 and responds with 'Hello, world!' to any incoming requests.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Middleware Support

This example shows how to use middleware with the h3 package. The middleware logs each incoming request's method and URL before passing control to the next handler.

const { createApp } = require('h3');
const { createServer } = require('http');

const app = createApp();

// Middleware to log requests
app.use((req, res, next) => {
  console.log(`${req.method} ${req.url}`);
  next();
});

app.use('/', (req, res) => {
  res.end('Hello, world!');
});

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Routing

This code demonstrates how to set up routing with the h3 package. It defines GET and POST routes for the '/hello' path, responding with different messages based on the HTTP method.

const { createApp, useRouter } = require('h3');
const { createServer } = require('http');

const app = createApp();
const router = useRouter();

router.get('/hello', (req, res) => {
  res.end('Hello, GET!');
});

router.post('/hello', (req, res) => {
  res.end('Hello, POST!');
});

app.use(router);

createServer(app).listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

Other packages similar to h3

FAQs

Package last updated on 02 Aug 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with āš”ļø by Socket Inc