Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 820 Bytes

README.md

File metadata and controls

48 lines (32 loc) · 820 Bytes

uFileCache

A minimal static file cache handler for uWebSocket.js

NOTE: Only for small files.

Installation

Add the following to your package.json file:

{
  "dependencies": {
	"uFileCache": "github:erf/uFileCache"
  }
}

Then run npm install.

Usage

// import the modules 
import uWS from 'uWebSockets.js'
import FileCache from 'uFileCache'

const fileCache = new FileCache()

// load files in folder to memory
fileCache.init('public')

// create a new app
const app = uWS.App()

// index.html
app.get('/', (res, req) => fileCache.send('./public/index.html', res))

// static files
app.get('/*', (res, req) => fileCache.send(`./public${req.getUrl()}`, res))

Test

node --test --no-warnings=ExperimentalWarning