serve
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@zeit/schemas | 2.29.0 | 6.72 kB | MIT | prod | |
ajv | 8.11.0 | 214.11 kB | MIT | prod | |
arg | 5.0.2 | 5.49 kB | MIT | prod | |
boxen | 7.0.0 | 6.81 kB | MIT | prod | |
chalk-template | 0.4.0 | 3.91 kB | MIT | prod | |
chalk | 5.0.1 | 12.98 kB | MIT | prod | |
clipboardy | 3.0.0 | 361.44 kB | MIT | prod | |
compression | 1.7.4 | 7.64 kB | MIT | prod | |
is-port-reachable | 4.0.0 | 1.98 kB | MIT | prod | |
serve-handler | 6.1.5 | 13.8 kB | MIT | prod | |
update-check | 1.5.4 | 4.51 kB | MIT | prod | 1 |
Serve is a handy npm package designed to assist in serving static files, single page applications, or any static file whether on your device or on a local network. Its usability extends to providing a neat interface for listing directory contents. Serve is ideal for both personal device usage and for trying out your projects in a local network environment. However, for production stages, deploying your site using platforms like Vercel is recommended.
Using serve is straightforward and uncomplicated. For first time users, you can quickly get a feel of it by running npx serve
in your project's directory. For those who favor global packages, serve can also be installed globally using the command npm install --global serve
. After installation, serve can be executed within a project's directory by simply running the command serve
.
Here's a simple example:
> npm install --global serve
> serve
You can also specify the folder you want to serve by including the folder name in the command. Like so:
> serve folder-name/
To explore more about the different options available in serve, just run serve --help
.
For serve's documentation, you can consult the serve-handler
page on Github at https://github.com/vercel/serve-handler#options to customize serve's behavior. You can create a serve.json
file and insert any of the properties listed on the page.
In terms of API usage, serve-handler can be incorporated as middleware in pre-existing HTTP servers. For instance:
const handler = require('serve-handler');
const http = require('http');
const server = http.createServer((request, response) => {
// You pass two more arguments for config and middleware
// More details here: https://github.com/vercel/serve-handler#options
return handler(request, response);
});
server.listen(3000, () => {
console.log('Running at http://localhost:3000');
});
In-depth information about serve's features, command syntax, and more can be found with the aforementioned resources.