Flare-k

Add babel and middleware

1 +{
2 + "presets": ["@babel/preset-env"]
3 +}
4 +/*
5 +원하는 node.js와 JS와 관련된 모든 설정을 집어넣는다.
6 + 파일은 Babel을 설정하는 곳이다. Babel이 실행되기 전에 파일을 찾아보고
7 +설정해둔 Preset을 읽고 이해한다. Preset에 따라 변환한다.
8 +*/
...\ No newline at end of file ...\ No newline at end of file
1 -const express = require("express"); 1 +import express from "express";
2 +import morgan from "morgan";
3 +import helmet from "helmet";
4 +import cookieParser from "cookie-parser";
5 +import bodyParser from "body-parser";
6 +
2 const app = express(); 7 const app = express();
3 const PORT = 80; 8 const PORT = 80;
4 9
...@@ -6,4 +11,15 @@ function handleListening() { ...@@ -6,4 +11,15 @@ function handleListening() {
6 console.log(`Listening on: http://localhost:${PORT}`); 11 console.log(`Listening on: http://localhost:${PORT}`);
7 } 12 }
8 13
14 +const sayHello = (req, res) => res.send("Hello~!");
15 +
16 +
17 +app.use(cookieParser());
18 +app.use(bodyParser.json());
19 +app.use(bodyParser.urlencoded({ extended: true }));
20 +app.use(helmet());
21 +app.use(morgan("dev"));
22 +
23 +app.get('/', sayHello);
24 +
9 app.listen(PORT, handleListening); 25 app.listen(PORT, handleListening);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 "description": "make Youtube Website", 4 "description": "make Youtube Website",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 - "test": "echo \"Error: no test specified\" && exit 1" 7 + "start": "nodemon --exec babel-node index.js --delay 2"
8 }, 8 },
9 "repository": { 9 "repository": {
10 "type": "git", 10 "type": "git",
...@@ -13,9 +13,16 @@ ...@@ -13,9 +13,16 @@
13 "author": "Kang Yeon Wook", 13 "author": "Kang Yeon Wook",
14 "license": "ISC", 14 "license": "ISC",
15 "dependencies": { 15 "dependencies": {
16 - "express": "^4.17.1" 16 + "@babel/core": "^7.9.6",
17 + "@babel/node": "^7.8.7",
18 + "@babel/preset-env": "^7.9.6",
19 + "body-parser": "^1.19.0",
20 + "cookie-parser": "^1.4.5",
21 + "express": "^4.17.1",
22 + "helmet": "^3.22.0",
23 + "morgan": "^1.10.0"
17 }, 24 },
18 - "scripts": { 25 + "devDependencies": {
19 - "start": "node index.js" 26 + "nodemon": "^2.0.4"
20 } 27 }
21 -}
...\ No newline at end of file ...\ No newline at end of file
28 +}
......