• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 쇼핑몰 만드는데 오류가 있어 문의드립니다.

쇼핑몰 만드는데 오류가 있어 문의드립니다.

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #63713

    김민주
    참가자
    새해 복 많이받으세요 선생님~!
    
    include부분이 계속 오류가 떠서 물어봅니다.
    
    겹치는 코드를 모듈화하여 newmodule.ejs 파일을 만들었고, 
    index.ejs에 포함하고 싶어서 index.ejs 파일에 <%- include('newmodule.ejs', {Module:result}) %>을 넣었더니
    계속 result가 없다고 오류가 뜹니다..
    서버에는 
    겹치는 코드 중 하나인 인덱스 파일 하나
    app.get('/',(req,res)=>{
        
        
    db.collection('content').find().toArray((error,result)=>{
        if(error) {
            console.log(error);
        }
        console.log(result);
        res.render('index.ejs',{Module:result});
    })
    })
    
    모듈화 파일 하나 이렇게 있습니다.
    app.get('/newmodule/:id',(req,res)=>{
        console.log(req.params.id);
        db.collection('content').findOne({_id:parseInt(req.params.id)},(error,result)=>{
            if(error) return console.log('error');
            console.log(result);
            res.render('newmodule.ejs',{Module:result});
        })
    })
    
    분명, content안의 db 파일들은 다 보여지고있긴하지만
    index.html에서 result가 없다고 오류가 뜨는데 그 이유가 무엇일까요ㅠ?
     
    
    
    #63714

    김민주
    참가자
    오류로는
    ( >> 92| <%- include('newmodule.ejs', {Module:result}) %>
        93|
        94|
        95|
    result is not defined),
    
    
    (Failed to load resource: the server responded with a status of 500 (Internal Server Error))
    
    총 두개 뜹니다.
    
    
    
    
    
    #63717

    codingapple
    키 마스터
    ejs파일에 {Module:Module} 해봅시다
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠