0

I'm using nodejs and Edge template to render dynamic data in HTMl elements , fed up with different solution but nothing seems working for me. I have used #App.locals, to declare the variable but getting function anonymous. So stick to original i want to return some data in x variable. I would appreciate your response , thank you.

code snippet : Example 1

const app =require(express)
const edge = require('edge.js')
app.use('*', (req, res, next) => {
edge.global('id', req.session.userId)
next()
});

here i'm getting an error as global is not a function

no luck so i run to different code

Example 2 :

const app =require(express)
var xvariable = {
id:"1"
}
app.use('*', (res, req, next) => {
app.locals = xvariable

console.log(id)  // expecting output as 1 but  getting function[asynchronous]

next()
});

  • This looks like an [xy problem](https://xyproblem.info/); please tell us what your goal is here. Inserting a variable into an express view? –  Feb 08 '22 at 09:20
  • Just Figure out , thanks to this post >> https://stackoverflow.com/questions/48400009/html-template-on-edge app.use('*', (req, res, next) => { app.locals.xvariable = req.session.userId next(); }); // > adding login page for Guest – Saurabh Kumar Feb 09 '22 at 07:56
  • Great, in that case feel free to delete this question –  Feb 09 '22 at 09:27

0 Answers0