프로그래밍 공부 메모/nodejs
module.export 사용 방법
jjs815
2023. 10. 7. 14:46
[ 모듈 만들어 내보내기 ]
function encrypt(data){
return `${data}가 암호화 되었습니다`;
}
function send(url, data){
const encryptedData = encrypt(data);
console.log(`${encryptedData}를 ${url}로 보냈습니다`)
}
module.exports = {
send
}
[ 사용시 ]
// 체인 메소드 없이 바로 사용
const { send } =require("./test");
// 체인 메소드 방식으로 사용 sendTest.send()
const sendTest = require("./test");
function makeRequest(url, data){
//요청 보내기
send(url);
//데이터를 리턴하기
return sendTest.read(data);
}
반응형