Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

53
Views
not so sure how to declare a variable that will use in nodeJS and rendering in HTML/template

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()
});

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs