Showing
1 changed file
with
20 additions
and
15 deletions
1 | -const express = require('express'); | 1 | +var express = require('express'); // ExpressJS 모듈을 추가 |
2 | -const path = require('path'); | 2 | +var app = express(); |
3 | -const app = express(); | 3 | +var bodyParser = require('body-parser'); // json 형태로 파싱할꺼니까 모듈 추가 |
4 | -app.use(express.static(path.join(__dirname, 'html'))); | 4 | + |
5 | -app.use((req, res, next) => { | 5 | +app.use(express.static(__dirname + '/views')); //public 폴더 안에 javascript 파일과 css파일을 모아둘 예정 |
6 | - console.log('안녕!'); | 6 | +app.use(bodyParser.json()); // body-parser 모듈을 사용해서 파싱 해줌 |
7 | - next(); | 7 | +app.engine('html', require('ejs').__express); |
8 | +app.set('views', __dirname + '/views'); // ejs 파일들을 저장하기 위해 경로 추가했음 | ||
9 | +app.set('view engine', 'ejs'); // ejs를 html로 바꿔주면 html로 파일 실행됩니다. | ||
10 | + | ||
11 | +app.get('/', function(req, res) { // 웹에서 실행할 주소가 localhost:3000/ 이거일때를 선언 | ||
12 | + res.render('googlemaps'); // first.ejs로 써도 되고 first만 써도 파일 실행을 해줍니다. | ||
8 | }); | 13 | }); |
9 | -app.get('/', (req, res) => { | 14 | + |
10 | - res.sendFile(path.join(__dirname, 'html', 'googlemaps.html')); | 15 | +app.get('/second/:something',function(req,res){ // 웹에서 실행할 주소가 localhost:3000/second/블라블라 이거일때를 선언 |
11 | -}); | 16 | +// something에 던질 데이터를 넣어준 것임 |
12 | -app.get('/about', (req, res) => { | 17 | +var something = req.params.something; |
13 | - res.sendFile(path.join(__dirname, 'html', 'about.html')); | 18 | +res.render('homepage',{data:something}); // render를 이용해서 값을 던져줌 |
14 | -}); | ||
15 | -app.listen(8080, () => { | ||
16 | - console.log('Express App on port 8080!'); | ||
17 | }); | 19 | }); |
20 | + | ||
21 | +app.listen(3000); //server 구동 포트 localhost:3000 여기에 쓰입니다. | ||
22 | +console.log("Server running on port 3000"); | ... | ... |
-
Please register or login to post a comment