2017-10-17 3 views
-2

개체 배열을 포함하고 .esj/.htlm 페이지와 함께 사용하려는 기능이 있습니다 (데이터 변수가 있다고 가정 함). 여기에 내가 가지고있는 것, 이것에 대해 가야하는 방법, 감사합니다!Express/EJS 서버 설정

app.get('/', (req, res) => { 
// want to get the data in here 
res.render('index', data); 
}) 

답변

0

기본 사항을 배우지 않은 것 같습니다. 다음과 같이 설정할 수 있습니다.

app.get('/', (req, res) => { 
     // call your function here 
     //normal sync function 
     data=function_name() 
     res.render('index', data); 

     //if you are using promisified function 
     function_name() 
     .then(data => { 
      res.render('index', data); 
     }).catch(error => { 
      console.log(error) 
      res.send(error) 
     }) 
    })