흔자
반응형

예시

'use strict';

const nconf = require('nconf');
const models_maria = require(nconf.get('models_maria'));

module.exports = async function(outCallback) {
    try {
        await models_maria.db.sync();
        outCallback(null, '==> MariaDb Connect Complete!!!\n');
    } catch (err) {
        outCallback(err);
    }
};

 

 

모듈과 라이브러리 불러오기

필요한 모듈과 라이브러리를 불러온다. 여기서는 구성 관리를 위한 nconf 라이브러리와 MariaDB와의 연결을 관리하기 위한 사용자 정의 모듈 models_maria를 사용한다.

'use strict';

const nconf = require('nconf');
const models_maria = require(nconf.get('models_maria'));

 

 

모듈 내보내기 및 연결 설정

이제 module.exports를 사용하여 MariaDB 연결을 설정하고 동기화하는 함수를 내보낸다. 이 함수는 outCallback이라는 인수를 받으며 이 인수는 MariaDB 연결에 대한 결과를 반환하는 데 사용되는 콜백 함수이다.

module.exports = async function(outCallback) {
    try {
        await models_maria.db.sync();
        outCallback(null, '==> MariaDb Connect Complete!!!\n');
    } catch (err) {
        outCallback(err);
    }
};

 

반응형
profile

흔자

@heun_n

즐겁게 개발하고 싶은 사람입니다.