Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript definitions for process.env.NODE_ENV?

Tags:

typescript

Is there a project with TypeScript definitions for "process" variable to use process.env.NODE_ENV? Couldn't find anywhere.

like image 344
Ross Khanas Avatar asked Feb 27 '16 07:02

Ross Khanas


People also ask

What is process env NODE_ENV?

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).

How do I view an env file in TypeScript?

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.

What is process env NODE_ENV === development?

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.


Video Answer


1 Answers

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; 
like image 100
RationalDev likes GoFundMonica Avatar answered Oct 14 '22 11:10

RationalDev likes GoFundMonica