Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

static-server

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

static-server

A simple http server to serve static resource files from a local directory.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
decreased by-81.15%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

Node static server

A simple http server to serve static resource files from a local directory.

Getting started

  • Install node.js
  • Install npm package globally npm -g install static-server
  • Go to the folder you want to serve
  • Run the server static-server

Options

-h, --help              output usage information
-V, --version           output the version number
-p, --port <n>          the port to listen to for incoming HTTP connections
-i, --index <filename>  the default index file if not specified
-f, --follow-symlink    follow links, otherwise fail with file not found
-d, --debug             enable to show error messages

Using as a node module

The server may be used as a dependency HTTP server.

Example

var StaticServer = require('static-server');
var server = new StaticServer({
  rootPath: '.',            // required, the root of the server file tree
  name: 'my-http-server',   // optional, will set "X-Powered-by" HTTP header
  port: 1337,               // optional, defaults to a random port
  host: '10.0.0.100',       // optional, defaults to any interface
  followSymlink: true,      // optional, defaults to a 404 error
  index: 'foo.html'         // optional, defaults to 'index.html'
});

server.start(function () {
  console.log('Server listening to', server.port);
});

server.on('request', function (req, res) {
  // req.path is the URL resource (file name) from server.rootPath
  // req.elapsedTime returns a string of the request's elapsed time
});

server.on('symbolicLink', function (link, file) {
  // link is the source of the reference
  // file is the link reference
  console.log('File', link, 'is a link to', file);
});

server.on('response', function (req, res, err, stat, file) {
  // res.status is the response status sent to the client
  // res.headers are the headers sent
  // err is any error message thrown
  // file the file being served (may be null)
  // stat the stat of the file being served (is null if file is null)

  // NOTE: the response has already been sent at this point
});

FAQ

  • Can I use this project in production environments? Obviously not.
  • Can this server run php, ruby, python or any other cgi script? No.
  • Is this server ready to receive thousands of requests? Preferably not.

License

The MIT License (MIT)

Keywords

FAQs

Package last updated on 08 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc