nodejs 에서 js 파일 실행하는데 오류가 납니다. 채택완료

5년 전 조회 4,589

Copy
function LivechatServerConfig(){
    this.db = new (() => { // db 설정
        this.host      = '127.0.0.1';
        this.port      = 3306;
        this.user      = 'root';
        this.password  = '1234';
        this.dbname    = 'test';
        this.charset   = 'utf8';
    })();
    this.main = new (() => { // 기본 설정
        this.port = 1121;
    })();
    this.table = new (() => { // 테이블 이름
        this.prefix  = 'g5_'; // 테이블 접두사
        this.member  = this.prefix+'member';
        this.livechat = this.prefix+'livechat';
        this.banlist = this.prefix+'livechat_banlist';
    })();
}

module.exports = new LivechatServerConfig();

 

오류가 발생하는 소스는 위 소스이고

 

서버에서 실행시

 

3034868304_1605435313.4185.png

 

이런 오류가 나옵니다.

 

3034868304_1605435348.2032.png

 

유효성 검사시 이 부분이 오류라는데

어떤 부분을 수정해야할까요?

 

항상 감사합니다!

 

 

 

 

답변 3개

채택된 답변
+20 포인트

소스에서 new 가 잘못쓰인것같습니다.

Copy
this.db = (() => { // db 설정

이렇게 하시면 될것같습니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

동일하게 구문오류가 나옵니다 ㅠㅠ
server.js 에서 LivechatServerConfig() 함수가 어떻게 쓰이는지 알필요가 있군요.

db 나 table 함수를 사용하는부분이 있는지?

댓글을 작성하려면 로그인이 필요합니다.

Copy
function LivechatServerConfig(){

    this.db = new function(){

        this.host      = '127.0.0.1';
        this.port      = 3306;
        this.user      = 'root';
        this.password  = '1234';
        this.dbname    = 'test';
        this.charset   = 'utf8';
    }();

    this.main = new function(){
        this.port = 1121;
    }();

    this.table = new function(){
        this.prefix  = 'g5_';
        this.member  = this.prefix+'member';
        this.livechat = this.prefix+'livechat';
        this.banlist = this.prefix+'livechat_banlist';
    }();
}

module.exports = new LivechatServerConfig();

 

이렇게 해보세요

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

https://opentutorials.org/course/3347/21185

를 참고해보세요

 

https://poiemaweb.com/nodejs-mysql

 

여기를 봐도 

접속시에 함수(메소드)내에서 db connection 처리가 좀 다른것 같습니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고