
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
static-server
Advanced tools
A simple http server to serve static resource files from a local directory.
A simple http server to serve static resource files from a local directory.
npm -g install static-server
static-server
-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
-n, --not-found <filename> the error 404 file
-c, --cors <pattern> Cross Origin Pattern. Use "*" to allow all origins
-z, --no-nocache disable cache (http 304) responses.
The server may be used as a dependency HTTP server.
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
cors: '*', // optional, defaults to undefined
followSymlink: true, // optional, defaults to a 404 error
templates: {
index: 'foo.html', // optional, defaults to 'index.html'
notFound: '404.html' // optional, defaults to undefined
}
});
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, file, stat) {
// 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
});
An special thank you to all contributors who allow this project to continue to evolve.
FAQs
A simple http server to serve static resource files from a local directory.
The npm package static-server receives a total of 16,817 weekly downloads. As such, static-server popularity was classified as popular.
We found that static-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.