Backend/Node.js
Node.js시작하기
섕걍
2023. 4. 26. 09:45
0. node.js를 설치한다
Node.js
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.
nodejs.org
node -v
npm -v
를 입력해서 버전과 설치를 확인하면 됨!
1. 서버를 만들자
01. 프레임워크 없이 만들기
const http = require('http');
http.createServer(function(req,res){
}).listen(8080,function(){
console.log('8080 server start');
})
02. 프레임워크 Express사용해서 만들기
npm i express
express를 설치합니다
const express = require('express');
const app = express();
app.get('/',function(req,res){
res.send('Express server');
});
app.listen(8080,function(){
console.log('8080 server start -express');
});
app.get으로 응답하는 코드를 설정해주고,
app.listen(8080)으로 8080서버를 만들은것!
node 파일명.js
로 입력해주고 localhost:8080을 입력해주면 서버 띄우기 완료~:)