1.0.19 • Published 6 months ago
jai-static v1.0.19
Jai Static
A simple and fast node.js module to serve static files effortlessly. Config base path and public folder path.
Features
- Easy Setup
- Works with any framework
Installation
Install my-project with npm
npm install jai-static
Usage / Examples
// 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/ ...');
});
API Reference
Options
Parameter | Type | Description |
---|---|---|
dir | string | destination folder path. (Required) |
basePath | string | base path to be used on server, default '/' (optional) |