Migrating from .env
Migrating from .env
CNOS migration works best as a bridge, not a flag day.
The pattern is:
- Keep
.cnosas the new source of truth. - Keep your current app/build/runtime working.
- Generate whatever bridge artifact the existing stack needs.
- Migrate direct env reads to CNOS app by app.
Use the migration assistant when you want help mapping existing env usage:
cnos migrate --scan src --dry-runcnos migrate --applycnos migrate --apply --rewritePlain Node or Express with .env
If your service currently starts with dotenv, keep that flow first.
cnos build env --profile local --to .env.localcnos build env --profile stage --to .env.stageThen your existing dotenv bootstrap keeps working.
Move server code gradually:
import cnos from '@kitsy/cnos';
await cnos.ready();
const port = cnos.readOr('value.server.port', 3000);const token = cnos.secret('app.token');For runtime packaging instead of env files:
cnos build server --profile prod --to .cnos-server.jsonVite Frontend
If you already use VITE_* env variables, keep that contract first.
cnos build public --framework vite --profile local --to .env.localcnos dev env --public --framework vite --profile local --to .env.local -- pnpm devThen add @kitsy/cnos-vite and migrate browser reads to:
import cnos from '@kitsy/cnos/browser';
cnos('public.app.apiBaseUrl');Next.js
If you already use NEXT_PUBLIC_*, keep that contract while adopting CNOS.
cnos build public --framework next --profile prod --to .env.productionThen wire @kitsy/cnos-next so Next gets public data from CNOS directly and browser code can read public.* through @kitsy/cnos/browser.
Webpack Static Frontend
If you already have a webpack.config.js, you do not need to invent a new runtime.
- read build-time settings such as dev-server port through
createCnos() - inject browser-safe config through
@kitsy/cnos-webpack - keep generated
.env.*files only if your repo still expects them
Example bridge:
cnos build public --profile local --to .env.localLonger-term path:
CnosWebpackPluginfor browser-safe valuescreateCnos()inside webpack config for build-time settings
pnpm Monorepo
For monorepos, do not copy .cnos into every package.
- keep one repo-root
.cnos/ - add
.cnosrc.ymlto each consuming app/package - optionally add a repo-root
.cnosrc.ymlif the root also consumes CNOS
Example:
root: ../../.cnosworkspace: travelServer-side packages can use projections:
cnos build server --workspace travel --profile prod --to apps/travel/.cnos-server.jsonLegacy env-based packages can still use:
cnos build env --workspace travel --profile local --to apps/travel/.env.localRecommended migration sequence:
- Keep
.cnosas the source of truth. - Generate
.env.*, browser, or server projection artifacts for legacy tools. - Migrate server code to
@kitsy/cnos. - Migrate browser code to
@kitsy/cnos/browser. - Remove handwritten env-file dependencies app by app.