A simple Node.js Express server with public API endpoints.
- ✅ Simple Express server
- ✅ Public API endpoints (no authentication required)
- ✅ CORS enabled for cross-origin requests
- ✅ JSON responses
- ✅ Error handling
- ✅ Development mode with auto-reload
- Install dependencies:
npm installnpm run devnpm startThe server will start on http://localhost:3000 (or the port specified in the PORT environment variable).
Returns information about available endpoints.
Response:
{
"message": "Welcome to CoinMachine API Server",
"endpoints": {
"GET /api/status": "Get server status",
"GET /api/hello?name=YourName": "Say hello",
"POST /api/echo": "Echo back posted data"
},
"timestamp": "2024-01-01T12:00:00.000Z"
}Returns the current server status.
Response:
{
"message": "Server is running!",
"timestamp": "2024-01-01T12:00:00.000Z",
"status": "online",
"version": "1.0.0"
}Returns a personalized greeting.
Query Parameters:
name(optional): The name to greet (defaults to "World")
Example:
GET /api/hello?name=Alice
Response:
{
"message": "Hello, Alice!",
"timestamp": "2024-01-01T12:00:00.000Z"
}Echoes back any JSON data sent in the request body.
Request Body: Any JSON object
Response:
{
"message": "Data received successfully",
"data": { "your": "data" },
"timestamp": "2024-01-01T12:00:00.000Z"
}You can test the API using curl, Postman, or any HTTP client:
curl http://localhost:3000/api/statuscurl "http://localhost:3000/api/hello?name=YourName"curl -X POST http://localhost:3000/api/echo \
-H "Content-Type: application/json" \
-d '{"message": "Hello World", "number": 42}'PORT: The port number to run the server on (default: 3000)
- express: Web framework for Node.js
- cors: Cross-Origin Resource Sharing middleware
- nodemon: Development dependency for auto-reloading (dev mode only)
MIT