1.0.19 • Published 6 months ago

jai-static v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Jai Static

A simple and fast node.js module to serve static files effortlessly. Config base path and public folder path.


Twitter Follow Linkedin: Harpal Singh

GitHub followers

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

ParameterTypeDescription
dirstringdestination folder path. (Required)
basePathstringbase path to be used on server, default '/' (optional)

Author: @hsk11