Skip to content

mmanueljoe/echo_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echo Server

A small TypeScript + Node.js HTTP server for practicing the fundamentals: routing, request/response, reading request bodies, and writing logs to disk.

Features

  • GET /echo: returns query-string params as JSON.
  • POST /echo: reads a JSON request body and returns it back as JSON.
  • CORS enabled (OPTIONS preflight supported).
  • Request logging to logs/requests.json (NDJSON: one JSON object per line).

Requirements

  • Node.js >= 18 (see package.json).
  • pnpm (optional; repo uses pnpm-lock.yaml).

Setup

  • pnpm install

If PowerShell blocks pnpm with an execution policy error, run the dev server with npx instead:

  • npx tsx watch src/server.ts

Run

Development (recommended):

  • pnpm dev

Build + run:

  • pnpm build
  • pnpm start

The server starts on http://localhost:3000 by default.

To change the port:

  • Windows PowerShell: $env:PORT = "4000"
  • macOS/Linux: PORT=4000

API

GET /echo

Example:

  • curl "http://localhost:3000/echo?name=Emmanuel&topic=node"

Response shape:

  • { "message": "...", "query": { ... }, "timestamp": "..." }

POST /echo

Example:

  • curl -X POST "http://localhost:3000/echo" -H "Content-Type: application/json" -d "{\"hello\":\"world\"}"

Response shape:

  • { "message": "...", "data": { ... }, "timestamp": "..." }

Logging

  • Logs are written to logs/requests.json.
  • The format is NDJSON (newline-delimited JSON): every request appends one line.
  • Each log entry includes: timestamp, method, pathname, body (raw body for POST), and hostname.

Project structure

  • src/server.ts: the server implementation (routing, request body reading, JSON responses, logging).
  • logs/: created at runtime if missing.
  • dist/: compiled output after pnpm build.

Concepts reference

For a glossary of the Node/HTTP concepts used here, see GLOSSARY.md.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors