You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@hapi/inert

Package Overview
Dependencies
Maintainers
7
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapi/inert

Static file and directory handlers plugin for hapi.js


Version published
Weekly downloads
160K
increased by21.48%
Maintainers
7
Created
Weekly downloads
 

Package description

What is @hapi/inert?

@hapi/inert is a static file and directory handler plugin for the Hapi.js framework. It allows you to serve static files and directories with ease, making it a useful tool for web applications that need to deliver static content such as images, CSS files, and JavaScript files.

What are @hapi/inert's main functionalities?

Serving Static Files

This feature allows you to serve static files from your server. In this example, a GET request to '/file' will serve the file located at 'path/to/your/file.txt'.

const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');

const init = async () => {
  const server = Hapi.server({
    port: 3000,
    host: 'localhost'
  });

  await server.register(Inert);

  server.route({
    method: 'GET',
    path: '/file',
    handler: {
      file: 'path/to/your/file.txt'
    }
  });

  await server.start();
  console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {
  console.log(err);
  process.exit(1);
});

init();

Serving Static Directories

This feature allows you to serve static directories. In this example, a GET request to '/directory/{param*}' will serve the files located in 'path/to/your/directory', with 'index.html' as the default file.

const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');

const init = async () => {
  const server = Hapi.server({
    port: 3000,
    host: 'localhost'
  });

  await server.register(Inert);

  server.route({
    method: 'GET',
    path: '/directory/{param*}',
    handler: {
      directory: {
        path: 'path/to/your/directory',
        index: ['index.html']
      }
    }
  });

  await server.start();
  console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {
  console.log(err);
  process.exit(1);
});

init();

Other packages similar to @hapi/inert

Readme

Source

@hapi/inert

Static file and directory handlers for hapi.js.

inert is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi – they work even better together.

Visit the hapi.dev Developer Portal for tutorials, documentation, and support

Useful resources

Keywords

FAQs

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc