Toggle navigation
Toggle navigation
This project
Loading...
Sign in
I_Jemin
/
Node-Study
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
I_Jemin
2018-03-24 00:31:49 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd741afee546de7d613f630574d44451d67ae35e
dd741afe
1 parent
a1ba2083
Handling GET Request
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
express-demo/index.js
express-demo/index.js
View file @
dd741af
const
express
=
require
(
'express'
);
const
app
=
express
();
const
courses
=
[
{
id
:
1
,
name
:
'course1'
},
{
id
:
2
,
name
:
'course2'
},
{
id
:
3
,
name
:
'course3'
},
];
// Corespond to HTTP
// app.get()
// app.post()
...
...
@@ -12,18 +18,17 @@ app.get('/',(req,res)=> {
});
app
.
get
(
'/api/courses'
,(
req
,
res
)
=>
{
res
.
send
(
[
1
,
2
,
3
]
);
res
.
send
(
courses
);
});
app
.
get
(
'/api/courses/:id'
,(
req
,
res
)
=>
{
res
.
send
(
req
.
params
.
id
);
const
course
=
courses
.
find
(
c
=>
c
.
id
===
parseInt
(
req
.
params
.
id
));
if
(
!
course
)
res
.
status
(
404
).
send
(
'The course with the given ID was not found'
);
res
.
send
(
course
);
});
app
.
get
(
'/api/courses/:year/:month'
,(
req
,
res
)
=>
{
res
.
send
(
req
.
query
);
});
// PORT
const
port
=
process
.
env
.
PORT
||
3000
;
app
.
listen
(
port
,()
=>
console
.
log
(
`Listening on port
${
port
}
...`
));
\ No newline at end of file
app
.
listen
(
port
,()
=>
console
.
log
(
`Listening on port
${
port
}
...`
));
...
...
Please
register
or
login
to post a comment