728x90
ํด๋ ๋ง๋ค๊ณ
1. npm init --yes
2. npm install express
3. package.json ์ ์๋์ ๊ฐ์ด ๋ณ๊ฒฝ
{
"name": "1.express-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start":"nodemon app"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
}
}
4. npm i nodemon --save-dev
ํ๊ณ (๋ด ํผ์จ์ ๋ ธ๋๋ชฌ์ด ์ ์ญ์ผ๋ก ๊น๋ ค์๋ค๊ณ ํ์ฌ๋, ๋ค๋ฅธ ๊ฐ๋ฐ์๋ค ๋ฐฐ๋ ค ์ฐจ์)
5. ํ์ ์ ๋ชจ๋๋ก
{
"name": "1.express-basic",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type":"module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
6. app.js ํ์ผ ๋ง๋ค์ด์ฃผ๊ณ ์๋ ์ฝ๋ ์์ฑ
import express from "express";
const app = express();
app.listen(8080);
7. npm start
8. ๋ก์ปฌ ํธ์คํธ 8080 ์ ์
9. ์ฝ๋๋ฅผ ์๋์ ๊ฐ์ด ๊ณ ์น๊ณ 8080 ์๋ก๊ณ ์นจ ํ์ ๋ Hello Node! ๋ง ์จ์ ธ ์์ผ๋ฉด ์ฑ๊ณตํ ๊ฒ์ด๋ค.
import express from "express";
const app = express();
app.get('/', (req, res, next)=>{
res.end('Hello Node!');
})
app.listen(8080);
728x90