Node.js, express, and using development versus production in app.configure

后端 未结 5 1489
孤城傲影
孤城傲影 2020-12-07 14:44

What is the easiest method to let express know what environment I am in? E.g. I want do do the below to make a connection to redis depending on what env I am in. Can this

5条回答
  •  难免孤独
    2020-12-07 15:48

    I did somthing even more comprehensive by ordering the sources of such parameters :

        var env = process.argv[2] || process.env.NODE_ENV || 'development'
        var mongourl = process.argv[3] || process.env.NODE_DB || 'mongodb://localhost/default'
        var port = process.env.PORT || 9001
    

    This way you can use command line args, env settings and default values.

提交回复
热议问题