
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@andyburke/fs-fastify
Advanced tools
A module to drive your fastify setup via the filesystem.
const fastify = require( 'fastify' )( {
logger: true
} );
const fs_fastify = require( '@andyburke/fs-fastify' );
const routes = await fs_fastify();
for ( const route of routes ) {
fastify.route( route );
}
fastify.listen( 3000, function ( err, address ) {
if ( err ) {
fastify.log.error( err );
process.exit( 1 );
}
fastify.log.info( `server listening on ${address}` );
} );
This will load all files that match the required options and register them as routes in your fastify server.
For example, you could lay out your files thusly:
./api
foo/
:bar/
GET.js
:baz/
POST.js
zip/
PATCH.js
This would create the following routes:
GET /foo/:bar
POST /foo/:baz
PATCH /foo/zip
Sets the root folder to find routes in. By default this is set to 'api'.
Sets the extensions to search for.
Sets the methods to look for in the file tree. Defaults to all normal HTTP methods.
Your routes should export either a single function, eg:
module.exports = function ( request, reply ) {
return {
hello: "world"
};
};
Or you can export a fastify route object, eg:
module.exports = {
// you should omit the method, as it will be filled by fs-fastify based on
// the filename
// method: 'GET',
// you should omit the url, as it will be filled by fs-fastify based on
// the filename
// url: '/',
schema: {
response: {
200: {
type: 'object',
properties: {
hello: { type: 'string' }
}
}
}
},
handler: function (request, reply) {
reply.send( { hello: 'world' } )
}
};
FAQs
Drive your fastify setup from the filesystem.
We found that @andyburke/fs-fastify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.