static-server-nodejs

0.1.1 • Public • Published

Static Server for NodeJS

Build Status Code Climate npm version

Available features

  1. No npm-dependencies;
  2. HTTP-methods: GET, HEAD, OPTIONS;
  3. CORS;
  4. Support simple cache with If-Modified-Since header
  5. Set any directory as public
  6. Set any file as index-file for server and for subdirectories of public directory
  7. Simple requests-log to console
  8. 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 is 3000
  • --public or -d - public directory. Default is ./public
  • --cors - CORS support. Default is false
  • --cache-headers - support simple cache with If-Modified-Since header. Default is false.
  • --index-file - name of custom index-file. Default is index.html.
  • --verbose - print request-log to console. Default is false.

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

Readme

Keywords

Package Sidebar

Install

npm i static-server-nodejs

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • belirafon