설정한 파일들을 실행시실 스크립트를 만듭니다. 개인적으로 파일이 재실행 될 때마다 나오는 메세지를
--quiet
또는-q
라는 flag로 감춰줍니다.
"start:dev": "npx nodemon -q"
1:1
사람(이름) - 주민번호
1:N
작성자 - 게시글
N:M
세탁업소 - 세탁물, 차량 - 차량 색
: 데이터베이스 테이블의 검색 속도를 향상시키기 위한 자료구조
아래와 같이 사용해서 app.js의 movies, users를 파일을 만들어 불러와 줄 것!
module.js : 내보낼
// const messages = ["hello world!", "안녕하세요"];
// const messages = { en: "hello world!", kr: "안녕하세요" };
// module.exports = messages
// const addition = (x, y) => x + y;
// module.exports = addition;
module.exports = {
addition: (x, y) => x + y,
multiple: (x, y) => x * y,
};
main.js : 불러올
//// module.exports
// const messages = require("./module");
// const lang = "en";
// console.log(messages);
// console.log(`zoo, ${messages[lang]}`); // zoo, hello world!
//// 객체구조분해할당
// const { en } = require("./module");
// console.log(`zoo, ${en}`); // zoo, hello world!
// //sum
// const sum = require("./module");
// console.log(sum(1, 2)); // 3
const Math = require("./module");
console.log(Math.addition(2, 5)); //7
console.log(Math.multiple(2, 5)); //10
// const { addition, multiple } = require("./module");
// console.log(addition(1, 5), multiple(2, 6)); //6, 12
function은 하나당 한 기능을 사용하는 것이 일반적!
fn.js
const currencyByCountry = {
en: {
format: "en-US",
currency: "USD",
},
kr: {
format: "kr-KO",
currency: "KRW",
},
};
const numberToCurrency = (number, countryCode) => {
const cur = currencyByCountry[countryCode];
return new Intl.NumberFormat(cur.format, {
style: "currency",
currency: cur.currency,
}).format(number);
};
const priceToKrwFormat = (price, country) => {
const countryCode = country || "kr";
return {
priceKrw: numberToCurrency(price, countryCode),
tax: numberToCurrency(Math.round((price / 11) * 10), countryCode),
originalPrice: numberToCurrency(Math.round(price / 11), countryCode),
};
};
console.log(priceToKrwFormat(100000, "kr"));
console.log(priceToKrwFormat(100000));
console.log(priceToKrwFormat(100000, "en"));