Create a Safe Node.js AI Project

Use a supported Node.js LTS release, a package manager, environment variables, and a server-side module layout. Keep provider-specific code behind a small adapter so your application logic does not depend on one SDK everywhere. Separate development, test, and production configuration. Add linting, type checking if using TypeScript, tests, and a .env.example containing placeholders rather than secrets.

For JavaScript projects, JSDoc can improve editor support; for larger systems, TypeScript is especially useful for tool arguments, structured outputs, and message-state models.

Note

Do not commit .env files containing secrets. Use a secret manager or protected deployment environment for production.

Minimal project structure
src/
  app.js
  config/env.js
  ai/provider.js
  ai/prompts.js
  ai/schemas.js
  tools/
  retrieval/
  evals/
  tests/
.env.example
package.json
💡 Keep provider calls, prompt definitions, tools, retrieval, and evaluations in separate modules. This structure makes it easier to test policy and domain behavior without calling a paid model for every unit test.
Key Takeaways
  • Use server-side configuration for secrets.
  • Separate prompts, tools, retrieval, and evaluation from route handlers.
  • Test domain logic without depending on live provider calls.
Knowledge Check

Why place provider calls behind an adapter?