How to create global variables accessible in all views using Express / Node.JS?

前端 未结 8 1055
半阙折子戏
半阙折子戏 2020-11-28 01:53

Ok, so I have built a blog using Jekyll and you can define variables in a file _config.yml which are accessible in all of the templates/layouts. I am currently

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 02:10

    In your app.js you need add something like this

    global.myvar = 100;
    

    Now, in all your files you want use this variable, you can just access it as myvar

提交回复
热议问题