Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박정인
/
opensource
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박정인
2017-12-07 22:30:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a4428b66d37f0bcff11b621573371c75cb77ccc8
a4428b66
1 parent
ce12ebb7
last
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
app.js
app.js
View file @
a4428b6
const
express
=
require
(
'express'
);
const
path
=
require
(
'path'
);
const
app
=
express
();
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'html'
)));
app
.
use
((
req
,
res
,
next
)
=>
{
console
.
log
(
'안녕!'
);
next
();
var
express
=
require
(
'express'
);
// ExpressJS 모듈을 추가
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
// json 형태로 파싱할꺼니까 모듈 추가
app
.
use
(
express
.
static
(
__dirname
+
'/views'
));
//public 폴더 안에 javascript 파일과 css파일을 모아둘 예정
app
.
use
(
bodyParser
.
json
());
// body-parser 모듈을 사용해서 파싱 해줌
app
.
engine
(
'html'
,
require
(
'ejs'
).
__express
);
app
.
set
(
'views'
,
__dirname
+
'/views'
);
// ejs 파일들을 저장하기 위해 경로 추가했음
app
.
set
(
'view engine'
,
'ejs'
);
// ejs를 html로 바꿔주면 html로 파일 실행됩니다.
app
.
get
(
'/'
,
function
(
req
,
res
)
{
// 웹에서 실행할 주소가 localhost:3000/ 이거일때를 선언
res
.
render
(
'googlemaps'
);
// first.ejs로 써도 되고 first만 써도 파일 실행을 해줍니다.
});
app
.
get
(
'/'
,
(
req
,
res
)
=>
{
res
.
sendFile
(
path
.
join
(
__dirname
,
'html'
,
'googlemaps.html'
));
});
app
.
get
(
'/about'
,
(
req
,
res
)
=>
{
res
.
sendFile
(
path
.
join
(
__dirname
,
'html'
,
'about.html'
));
});
app
.
listen
(
8080
,
()
=>
{
console
.
log
(
'Express App on port 8080!'
);
app
.
get
(
'/second/:something'
,
function
(
req
,
res
){
// 웹에서 실행할 주소가 localhost:3000/second/블라블라 이거일때를 선언
// something에 던질 데이터를 넣어준 것임
var
something
=
req
.
params
.
something
;
res
.
render
(
'homepage'
,{
data
:
something
});
// render를 이용해서 값을 던져줌
});
app
.
listen
(
3000
);
//server 구동 포트 localhost:3000 여기에 쓰입니다.
console
.
log
(
"Server running on port 3000"
);
...
...
Please
register
or
login
to post a comment