Getting Started
Get up and running with Kempo Server in just a few steps.
Installation
1. Install the npm package.
npm install kempo-server
2. Add it to your package.json scripts, use the --root flag to tell it where the root of your site is.
{
...
"scripts": {
"start": "kempo-server --root public"
}
...
}
3. Run it in your terminal.
npm run start
Basic Project Structure
Once installed, create a basic project structure:
my-project/
├─ public/ # Your web root
│ ├─ index.html # Homepage
│ ├─ styles.css # CSS files
│ ├─ api/ # API routes
│ │ ├─ hello/
│ │ │ ├─ GET.js # GET /api/hello/
│ │ ├─ users/
│ │ │ ├─ GET.js # GET /api/users/
│ │ │ ├─ POST.js # POST /api/users/
├─ package.json
├─ .config.json # Optional configuration
Your First Route
Create a simple API endpoint:
1. Create the directory structure
mkdir -p public/api/hello
2. Create your first route file
Create public/api/hello/GET.js:
// public/api/hello/GET.js
export default async function(request, response) {
const { name } = request.query;
const message = name ? `Hello ${name}!` : 'Hello World!';
response.json({ message, timestamp: new Date().toISOString() });
}
3. Test your route
Start your server and visit:
http://localhost:3000/api/hello/http://localhost:3000/api/hello/?name=World
Command Line Options
Kempo Server supports several command line options:
--root <path>- Set the document root directory (required)--port <number>- Set the port number (default: 3000)--host <address>- Set the host address (default: localhost)--config <path>- Set the configuration file path (default: .config.json)--verbose- Enable verbose logging
Basic example:
kempo-server --root public --port 8080 --host 0.0.0.0 --verbose
Configuration File Examples
You can specify different configuration files for different environments:
# Development
kempo-server --root public --config dev.config.json
# Staging
kempo-server --root public --config staging.config.json
# Production with absolute path
kempo-server --root public --config /etc/kempo/production.config.json
# Mix with other options
kempo-server --root dist --port 8080 --config production.config.json
What's Next?
Now that you have Kempo Server running, explore these topics:
- Learn about Routes & Routing - File-based routing, dynamic routes, and HTML routes
- Request & Response Objects - Working with HTTP requests and responses
- Configuration - Customize server behavior
- Middleware - Add authentication, logging, CORS, and more
- Examples & Demos - See real-world examples in action