Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
The serve npm package is a static file serving and directory listing package that allows you to serve static files over HTTP quickly and easily. It is often used for hosting single-page applications, static websites, or for serving files during development.
Serving static files
This command starts a static file server in the specified directory. By default, it listens on port 5000, but you can specify another port with the -l flag.
npx serve /path/to/static/files
Directory listing
Running serve without any arguments serves the current directory and provides a directory listing if no index.html file is found.
npx serve
Single-page application mode
The -s flag enables single-page application mode, which rewrites all not-found requests to /index.html, allowing for client-side routing.
npx serve -s /path/to/spa
Custom port
This command starts the server on a custom port, in this case, port 4000.
npx serve -l 4000
SSL/TLS
Serve can also provide content over HTTPS by specifying the paths to the SSL certificate and key files.
npx serve --ssl-cert /path/to/cert.pem --ssl-key /path/to/key.pem
http-server is a simple, zero-configuration command-line HTTP server. It is powerful and has more configuration options than serve, such as the ability to cache files, set cache headers, and use proxies.
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Unlike serve, which is focused on static content, Express can handle dynamic content, middleware, routing, and much more.
lite-server is a lightweight development server that serves a web app, opens it in the browser, and refreshes the browser on file changes. It is built on top of BrowserSync and is more suited for small projects and quick prototyping compared to serve.
Simple 5 minute command-line file / directory server built with connect, inspired by nodejitsu's http-server to show off the simplicity and flexibility of connect as a modular server.
$ npm install -g serve
Usage: serve [options] [dir]
Options:
-v, --version output the version number
-F, --format <fmt> specify the log format string
-p, --port <port> specify the port [3000]
-f, --favicon <path> serve the given favicon
-H, --hidden enable hidden file serving
-C, --cors allows cross origin access serving
-S, --no-stylus disable stylus rendering
-J, --no-jade disable jade rendering
--no-less disable less css rendering
-I, --no-icons disable icons
-L, --no-logs disable request logging
-D, --no-dirs disable directory serving
--compress gzip or deflate the response
--exec <cmd> execute command on each request
-h, --help output usage information
HTTP Accept support built into connect.directory()
:
$ curl http://local:3000/ -H "Accept: text/plain"
bin
History.md
node_modules
package.json
Readme.md
Requesting a file:
$ curl http://local:3000/Readme.md
# serve
...
Requesting JSON for the directory listing:
$ curl http://local:3000/ -H "Accept: application/json"
["bin","History.md","node_modules","package.json","Readme.md"]
Directory listing served by connect's connect.directory()
middleware.
(The MIT License)
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Static file serving and directory listing
The npm package serve receives a total of 634,582 weekly downloads. As such, serve popularity was classified as popular.
We found that serve demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers 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
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.