static-server-nodejs
v0.1.1
Published
Simple static server for Nodejs
Downloads
10
Readme
Static Server for NodeJS
Available features
- No npm-dependencies;
- HTTP-methods:
GET
,HEAD
,OPTIONS
; - CORS;
- Support simple cache with
If-Modified-Since
header - Set any directory as public
- Set any file as index-file for server and for subdirectories of public directory
- Simple requests-log to console
- Ready to run out of box
CLI Run
node ./bin/nodess
or with npm
npm start
CLI Parameters & Options
--help
- show help information about cli-configuration.--port
or-p
- port for listening. Default is3000
--public
or-d
- public directory. Default is./public
--cors
- CORS support. Default isfalse
--cache-headers
- support simple cache withIf-Modified-Since
header. Default isfalse
.--index-file
- name of custom index-file. Default isindex.html
.--verbose
- print request-log to console. Default isfalse
.
Examples
const createStaticServer = require('static-server-nodejs');
const path = require('path');
const PORT = process.env.NODESS_PORT || 3000;
let staticServer = createStaticServer(path.join(__dirname, './public'),{
cors: true,
cache: true,
indexFile: 'index.html',
verbose: true
})
.listen(PORT, '127.0.0.1', () => {
console.log(`Server run and listen on ${PORT} port.`);
});
For examples, please, see ./examples/*
or tests ./test/*
.
Tests
Tests require Mocha.
mocha ./tests
or with npm
npm test
Test coverage with Istanbul
npm run coverage
Road map
- extended cache-headers support
- gzip support
- support multipart/*
- create npm-package
License
Licensed under the MIT License