Socket
Socket
Sign inDemoInstall

@tinyhttp/app

Package Overview
Dependencies
Maintainers
1
Versions
305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/app

0-legacy, tiny & fast web framework as a replacement of Express


Version published
Weekly downloads
110K
increased by0.68%
Maintainers
1
Weekly downloads
 
Created

What is @tinyhttp/app?

@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.

What are @tinyhttp/app's main functionalities?

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'));

Other packages similar to @tinyhttp/app

Keywords

FAQs

Package last updated on 04 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