Skip to content

About

A Node.js API service

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

nodejs-api-2

A Node.js (Express) API scaffolded from the Atlas Node.js API Service template — pre-wired with Elastic APM, a Winston logger, a hardened multi-stage Dockerfile and a GitHub Actions CI/CD pipeline.

Folder structure

src/
├── index.js                # bootstrap: starts APM, creates app, listens, graceful shutdown
├── app.js                  # Express app factory (testable without a port)
├── config/
│   ├── apm.js              # Elastic APM agent (loaded first)
│   └── index.js            # environment-driven config
├── lib/
│   └── logger.js           # Winston logger (JSON in prod, pretty in dev)
├── middleware/
│   ├── requestContext.js   # correlation id + per-request child logger
│   ├── requestLogger.js    # structured access log with latency
│   ├── notFoundHandler.js  # 404 -> error handler
│   └── errorHandler.js     # central error responder
├── routes/
│   ├── index.js            # router aggregation
│   └── health.routes.js
└── controllers/
    └── health.controller.js
test/                       # jest + supertest

Develop

npm install
cp .env.example .env
npm run dev        # auto-reload
npm test           # jest + supertest
npm run lint

The API listens on PORT (default 3000). Health check: GET /healthz.

Observability

  • APM — set ELASTIC_APM_SERVER_URL (and optionally ELASTIC_APM_SECRET_TOKEN) to enable the agent; it stays off locally when unset.
  • Logging — import src/lib/logger; every request log carries a requestId correlation id (also returned in the X-Request-Id header).

Docker

docker build -t nodejs-api-2 .
docker run -p 3000:3000 nodejs-api-2

CI/CD

.github/workflows/ci.yaml runs install → lint → test on every push/PR, then builds and (on main) publishes a container image to GitHub Container Registry.

About

A Node.js API service

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages