mohammadhasanii / Node-HTTP3

This project showcases building fast and lightweight web apps in Node.js using H3 framework, with superior security and speed on HTTP/3. It's a great alternative to Express or Node.js and has features like routing, fast processing, and interaction with other frameworks.

Home Page:https://www.cloudflare.com/learning/performance/what-is-http3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node-HTTP3

This project is a simple example of a web application in Node.js using the H3 framework. The main goal is to demonstrate how to use the H3 framework to build fast and lightweight web applications. Additionally, since H3 works directly on HTTP/3, it has security features and higher speed compared to HTTP/1 and HTTP/2.

H3 is a lightweight and fast framework for building web applications that works directly on HTTP/3. It uses technologies such as async/await and Promise for processing web requests and has features such as routing, fast processing, and interaction with other frameworks.

The superiority of H3 over Express or Node.js lies in its processing speed.

Example Image

Installation

To install the dependencies, run the following command:

npm install

Usage

To start the server, run the following command:

npm start

This will start the server on port 3000. You can then visit http://localhost:3000/ in your web browser to see the "Hello World!" message.

You can also visit http://localhost:3000/hello/{name} to see a personalized message that includes the name you specify in the URL.

Code Overview

The code starts by importing the necessary modules and creating an H3 app:

import { createServer } from 'node:http';
import { createApp, eventHandler, createRouter, toNodeListener } from 'h3';

const app = createApp();
It then creates an H3 router that handles requests to the root path ("/") and the "/hello/{name}" path:

const router = createRouter()
    .get('/', eventHandler(() => 'Hello World!'))
    .get('/hello/:name', eventHandler((event) => `Hello ${event.context.params.name}!`)
    );

app.use(router);
Finally, it creates an HTTP server using Node.js and starts listening for incoming requests:

createServer(toNodeListener(app)).listen(process.env.PORT || 3000);
console.log('app is running on port 3000');

Run application

node app.js

About

This project showcases building fast and lightweight web apps in Node.js using H3 framework, with superior security and speed on HTTP/3. It's a great alternative to Express or Node.js and has features like routing, fast processing, and interaction with other frameworks.

https://www.cloudflare.com/learning/performance/what-is-http3/


Languages

Language:JavaScript 100.0%