반응형
예시
'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);
}
};
반응형
'Develop > Node.js' 카테고리의 다른 글
[Node.js] npm install 옵션 --save와 --save-dev의 차이점 (0) | 2023.02.08 |
---|---|
[Node.js] MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 오류 해결 (0) | 2023.01.18 |
[Node.js] 백그라운드 실행과 모니터링 패키지 pm2 설치하기 - 2 (0) | 2023.01.13 |
[Node.js] 백그라운드 실행과 모니터링 패키지 pm2 설치하기 - 1 (0) | 2023.01.13 |