1.0.0 • Published 4 years ago

@dubbyyt/express-fs v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Express-FS

Express-FS is a middleware for Express that will allow you to specify a directory and have it route requests through your File System.

Setup/Installing:

npm i @dubbyyt/express-fs

How To Use

// server.js
const express = require("express");
const app = express();

//PUT ANY OTHER MIDDLEWARES BEFORE THIS LINE
app.use(require('@dubbyyt/express-fs')(directory));

//Do not use app.post and app.get, etc anymore.

Replace directory with the directory you wish to run the File System routing off of.

// /test/index.js or /test/randomname.js
// ^ Links to: /test/ | ^ Links to /test/randomname

//Actual callback
module.exports = function(req,res){
    res.send("Hello world!");
}

module.exports.method = "GET" // Method of request.

//Optional
module.exports.required = {
    headers: ["required-header"], //Place required header names in here. Will deny requests without header to this path with an Error 400.
    body: ["required-body"] //Place required body names in here. This will deny requests without the name(s) in the body with an Error 400.
}

How to form your filesystem:

It's just like a website and if it we're formed.

IE,

/dir/index.js => /dir/
/dir/helloworld.js => /dir/helloworld

and

/dir/helloworld/index.js => /dir/helloworld/