
크롬의 JS엔진 V8을 떼어놓은 event-driven, non-blocking I/O 의 특성을 가진 실행환경 블라블라
express 설치하기
//node.js 설치 후
npm init
entry point: (index.js) 원하는 파일명
npm install express
서버를 띄우기 위한 기본세팅
const express = require('express');
const app = express();
app.listen(포트번호, 실행할 코드);
로컬서버와 연동하기
//터미널
node 파일명.js
이렇게 수동으로 할 수도 있지만, 변경사항이 생길 때마다 crtl+c 로 종료 후 다시 선언 해주어야 한다. 그래서 nodemon 으로 자동화 해줄것이다.
npm install -g nodemon
보안오류 생길 시
관리자 권한으로 PowerShell 실행해주고
app.get('/경로', function (요청, 응답) {
응답.send('get요청 하셨네유');
응답.sendFile(__dirname + '/파일경로 예) index.html sub.html')
});
app.use(express.urlencoded({extended: true})) //post로 요청한 값 url 인코딩으로 알아서 해석해서 가져오기
app.post('/경로', function (요청, 응답) {
응답.send('전송완료');
console.log(요청.body);
});