serve-og
v1.0.0
Published
A simple Node.js server designed to serve static files and provide basic error handling for development and testing purposes.
Downloads
10
Maintainers
Readme
serve-og
Simple & lightweight.
Overview
serve-og
is a lightweight Node.js server designed for serving HTML files locally. Ideal for development and testing, this package allows you to quickly set up a local server that serves static HTML files from a specified directory.
Features
- Serve an HTML file from a specified directory
- Configuration
- Basic security with Helmet
- Request logging with Morgan
Getting Started
Prerequisites
Ensure you have Node.js and npm installed on your machine.
Installation
- Install the package:
npm install serve-og
This command will automatically install all dependencies, including nodemon
for development.
Default Configuration
By default, the server is configured with:
- Port:
3000
- Directory:
src
- File:
index.html
- Server Name:
Local Server
These can be overridden by specifying environment variables when starting the server.
Usage[with default config]
Run the Server in Development Mode:
- Use the following command to start the server:
serve.dev
Run the Server in Production Mode:
- Use the following command to start the server:
serve.prod
Environment Variables[custom deployment]
You can customize the server behavior by setting environment variables. The following variables are available:
PORT
: Port number for the server (default is 3000).DIRECTORY
: Directory containing the HTML file (default issrc
).FILE
: HTML file to serve (default isindex.html
).SERVER_NAME
: Name of the server (default is "Local Server").
To use environment variables, you can set them inline with the command or create a .env
file in the project root.
Example with environment variables:
PORT=4000
DIRECTORY=public
FILE=sample.html
SERVER_NAME="My Server"
serve.dev
Manually Restarting the Server
While nodemon is running, you can manually restart the server by typing rs
in the terminal.
Example Output
When you run the server with nodemon, you should see output similar to the following:
- `> [email protected] start`
- `> nodemon scripts/server.js test sample.html test`
- `[nodemon] 3.1.4`
- `[nodemon] to restart at any time, enter rs`
- `[nodemon] watching path(s): *.*`
- `[nodemon] watching extensions: js,mjs,cjs,json`
- `[nodemon] starting node scripts/server.js test sample.html test`
- `Local Server running at http://localhost:3000`
- `Serving "index.html" from "src"`
Notes
- The
index.html
file should be placed in thesrc
folder (if running default).
License
This project is licensed under the MIT License - see the LICENSE file for details.