const odd = '홀수입니다.';
const even = '짝수입니다.';
module.export = {
odd,
even
}
export.odd = odd;
export.even = even;
// 이렇게도 보낼수 있으나
module.export = {}
// 를 사용한 순간 odd와 even은 export 되지 않는다.
const value = require('./경로');
// or
const {odd, even} = require('./경로');
import, from 문법을 사용할수는 있으나 지금까지 사용해온 방법대로 사용하는것 같다.
console.time, consoletimeEnd: 시간이 얼마나 걸렸는지 로깅
console.time('같은말')
// ...
console.timeEnd('같은말')
console.error: 에로 로깅
console.log: 평범한 로깅
console.dir: 객체 로깅
console.trace: 호출 스택 로깅
console.table: 테이블로 로깅
console.table([{name: 'dong', birth: 1994}, {name: 'hero', birth: 1988}])
setTimeout(콜백함수, 밀리초): 주어진 밀ㄹ리초 이후에 콜백함수 실행
const name = setInterval(콜백함수, 밀리초): 밀리초마다 함수 실행, name으로 취소
setImmediate(콜백함수): 즉시 실행
clearTimeout(아이디): setTimeout 취소
clearInterval(아이디): setInterval 취소
clearImmediate(아이디): setImmediate 취소
ㅡㅡfilename: 현재 파일 경로
ㅡㅡdirname: 현재 폴더 경로
(ㅡㅡ: dunder, dunderscore)
console.log(this) // {}
console.log(this === module.exports) // true
function a() {
console.log(this === global); // true
}
// 위의 말에 따라 this === module.exports이므로
this.odd = odd;
this.even = even;
// 같이 export 할순 있긴 하다.
// dep1.js
require(./dep2)
// dep2.js
require(./dep1)
서로가 서로를 불러오게 되면 무한히 반복되게 된다
이를 막기위해 node에서 빈 객체가 require된다.
https://nodejs.org/dist/latest-v19.x/docs/api/os.html
공식문서
node >> proecess 접근
... 등등 다양하다
process.cwd() 로 경로체크를 자주 한다.
https://nodejs.org/dist/latest-v19.x/docs/api/path.html
공식문서
const path = require('path')
const string = __filename;
console.log("path.sep:", path.sep);
console.log("path.delimiter:", path.delimiter);
console.log("--------------");
console.log("path.dirname():", path.dirname(string));
console.log("path.extname():", path.extname(string));
console.log("path.basename():", path.basename(string));
console.log(
"path.basename - extname:",
path.basename(string, path.extname(string))
);
console.log('--------------')
console.log('path.parse():', path.parse(string));
console.log('path.normalize():', path.normalize(...))
// 경로에 // \\\ 이러한것들을 평탄화..?
console.log('--------------')
console.log('path.isAbsoute(C:\\):', path.isAbsolute('C:\\'));
console.log('path.isAbsolute('./home')', path.isAbsolute('./home'))
// ... 등등등
위에는 node방식 아래는 WHATWG방식