Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김대휘
/
Node.js-Express-Assignment1
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
김대휘
2020-05-02 02:20:42 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d028084e65c5c19e1306ddfaac8e9c4b416c8695
d028084e
0 parents
First commit
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
.gitignore
app.js
package.json
.gitignore
0 → 100644
View file @
d028084
node_modules
package-lock.json
yarn.lock
\ No newline at end of file
app.js
0 → 100644
View file @
d028084
var
express
=
require
(
'express'
);
var
app
=
express
();
var
bodyParser
=
require
(
'body-parser'
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
var
books
=
new
Array
();
app
.
get
(
'/books/:bookId'
,
function
(
req
,
res
)
{
var
bookId
=
req
.
params
.
bookId
;
console
.
log
(
books
[
bookId
]);
res
.
send
(
books
[
bookId
]);
});
/*
* json representation of book object
{
"id" : 2,
"name" : "book2",
"price" : 2000,
"author" : "jin"
}
*/
app
.
post
(
'/books'
,
function
(
req
,
res
)
{
// Create book information
books
[
req
.
body
.
id
]
=
[
req
.
body
.
id
,
req
.
body
.
name
,
req
.
body
.
price
,
req
.
body
.
author
];
res
.
send
(
books
[
req
.
body
.
id
]);
})
app
.
put
(
'/books'
,
function
(
req
,
res
)
{
books
[
req
.
body
.
id
]
=
[
req
.
body
.
id
,
req
.
body
.
name
,
req
.
body
.
price
,
req
.
body
.
author
];
res
.
send
(
books
[
req
.
body
.
id
]);
})
app
.
delete
(
'/books/:bookId'
,
function
(
req
,
res
)
{
var
index
=
req
.
param
(
'bookId'
);
console
.
log
(
index
);
if
(
index
>
-
1
)
{
books
.
splice
(
index
,
1
);
}
res
.
send
(
req
.
param
(
'bookId'
));
})
var
server
=
app
.
listen
(
80
);
console
.
log
(
books
);
\ No newline at end of file
package.json
0 → 100644
View file @
d028084
{
"dependencies"
:
{
"express"
:
"^4.17.1"
}
}
Please
register
or
login
to post a comment