Global Variable in app.js accessible in routes?

前端 未结 13 1641
南笙
南笙 2020-11-28 21:29

How do i set a variable in app.js and have it be available in all the routes, atleast in the index.js file located in routes. using the express fra

13条回答
  •  暖寄归人
    2020-11-28 22:19

    the easiest way is to declare a global variable in your app.js, early on:

    global.mySpecialVariable = "something"
    

    then in any routes you can get it:

    console.log(mySpecialVariable)
    

提交回复
热议问题