How to start node app with development flag?

前端 未结 5 563
梦如初夏
梦如初夏 2021-02-07 05:41

At top of my app.js file I put

NODE_ENV=\'development\';

but I get error that NODE_ENV is not defined. But in the nodejs documentation is says

5条回答
  •  清歌不尽
    2021-02-07 06:19

    If you want to set an environment variable in your js file you should do it this way:

    process.env.NODE_ENV = 'development';
    

    Alternatively you can set the variable in your shell and run your application:

    $ NODE_ENV="development" node ./app.js
    

    or export the variable and run your application:

    $ export NODE_ENV="development"
    $ node ./app.js
    

    On Windows:

    $ set NODE_ENV="development"
    $ node app.js
    

提交回复
热议问题