node.js 공부 정리

const fs = require("fs"); fs 모듈 불러오기
fs.writeFileSync("notes.txt", "hii"); notes.txt파일 생성 및 내용 입력

fs.appendFileSync("notes.txt", " 한국산다"); notes.txt파일에 내용 추가

node는 'a', 'b'파일간에 기본적으로 그냥 변수 공유가 불가능하다

그럴때는 module.exports를 이용하여 변수를 사용할수 있다.

a에서

const name = require("./utils");
console.log(name);

b에서

const name = "lee";

module.exports = name;

하면 변수를 사용이 가능하다

node.js 에서 깃사용시 node_modules를 올리지 않는 방법
.gitignore을 생성하여
node_modules/ 을 추가하면 된다

validator 이메일,URL등 유효성을 검사해주는 모듈

chalk 로그를 색,bg색,굵기등등 나타내주는 모듈

nodemon 저장하면 바로 서버가 다시 자동으로 실행해주는 모듈

yargs 커맨드라인 인수를 분석하고 사용자 인터페이스를 생성하여 대화형 커맨드 라인을 구축할 수 있는 모듈

좋은 웹페이지 즐겨찾기