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

@fastify/autoload

Package Overview
Dependencies
Maintainers
20
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/autoload

Require all plugins in a directory

  • 6.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
20
Created

What is @fastify/autoload?

@fastify/autoload is a Fastify plugin that allows you to automatically load plugins, routes, and other modules from a specified directory. This helps in organizing your Fastify application by separating different functionalities into different files and directories, making the codebase more modular and maintainable.

What are @fastify/autoload's main functionalities?

Auto-loading Plugins

This feature allows you to automatically load all plugins from a specified directory. In this example, all plugins in the 'plugins' directory will be registered with the Fastify instance.

```javascript
const fastify = require('fastify')();
const autoload = require('@fastify/autoload');
const path = require('path');

fastify.register(autoload, {
  dir: path.join(__dirname, 'plugins')
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});
```

Auto-loading Routes

This feature allows you to automatically load all routes from a specified directory. In this example, all route files in the 'routes' directory will be registered with the Fastify instance.

```javascript
const fastify = require('fastify')();
const autoload = require('@fastify/autoload');
const path = require('path');

fastify.register(autoload, {
  dir: path.join(__dirname, 'routes')
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});
```

Custom Options

This feature allows you to pass custom options to the autoload plugin. In this example, all modules in the 'services' directory will be registered with a prefix of '/api'.

```javascript
const fastify = require('fastify')();
const autoload = require('@fastify/autoload');
const path = require('path');

fastify.register(autoload, {
  dir: path.join(__dirname, 'services'),
  options: { prefix: '/api' }
});

fastify.listen(3000, err => {
  if (err) throw err;
  console.log('Server listening on http://localhost:3000');
});
```

Other packages similar to @fastify/autoload

Keywords

FAQs

Package last updated on 08 Oct 2024

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