Node
Node.js 복습 #1 nodemon, __dirname , static 파일 설정
곽빵
2020. 6. 20. 17:03
$ npm install nodemon -g
코드 변경을 자동으로 감지해서 서버를 올렸다 내렸다하는 플러그인
-g : 내 pc의 어느 디렉토리에서든지 사용한다는 말
사용법
$ nodemon app.js
$ nodemon app.js localhost 3000
$ nodemon --debug app.js 80
Routing 처리
app.get('/', function(req,res){
res.sendFile(__dirname + "/public/index.html");
});
__dirname : node에서 현재 파일의 경로를 제공해주는 변수
static 디렉토리 설정 (해당 디렉토리 안에 있는 파일들이 자동으로 등록)
app.use(express.static('public'));