A simple and fast node.js module to serve static files effortlessly. Config base path and public folder path.
- Easy Setup
- Works with any framework
Install my-project with npm
npm install jai-static
// Express
const express = require('express');
const JaiStatic = require('jai-static');
const app = express();
const port = 1111;
app.get('*', JaiStatic({
dir: `${__dirname}/public`, // public folder
}));
app.listen(port, () => {
console.log(`Server listening on http://localhost:${port}/ ...`);
});
// OR Http
const http = require('http');
const JaiStatic = require('jai-static');
const server = http.createServer(async (req, res) => {
JaiStatic({
dir: `${__dirname}/public`, // public folder
})(req, res, () => { /* do something after */ });
});
server.listen(1111, () => {
console.log('Server listening on http://localhost:1111/ ...');
});
Parameter | Type | Description |
---|---|---|
dir |
string |
destination folder path. (Required) |
basePath |
string |
base path to be used on server, default '/' (optional) |