Is there a project with TypeScript definitions for "process" variable to use process.env.NODE_ENV? Couldn't find anywhere.
NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).
let env = process. env["NODE_ENV"]; Alternatively, as jcalz pointed out in the comments, if you're using TypeScript 2.2 or newer, you can access indexable types like the one defined above using the dot syntax - in which case, your code should just work as is.
process. env is a reference to your environment, so you have to set the variable there. To set an environment variable in Windows: SET NODE_ENV=development. on macOS / OS X or Linux: export NODE_ENV=development. Follow this answer to receive notifications.
Update for Node 8:
Now env
is declared as ProcessEnv
in DefinitelyTyped.
env: ProcessEnv; export interface ProcessEnv { [key: string]: string | undefined; }
TypeScript 2 supports npm package type definitions for node. It currently uses the DefinitivelyTyped node.d.ts.
npm install --save-dev @types/node
Pre Node 8 version:
process env
is declared as any
in DefinitelyTyped node.d.ts.
env: any;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With