on
Express JS Crash Course ... continued
I’ve started to work on my project and have put some basics in place.
I have started to build the data model with Mongoose. I’ve watched some additional videos, and searched documentation and samples on-line. I will be adding comments to my code to refenrence all the different sources that I have used. It is useful to have these “bookmarked” within the project for future reference, too.
I will continue to watch the Crash Course on Express JS.
members = [
{ id:1, name: 'John Doe', email: 'jd@email.com', status:'a'},
{ id:2, name: 'John Doe Sr', email: 'jd.sr@email.com', status:'a'},
{ id:2, name: 'John Doe Jr', email: 'jd.jr@email.com', status:'a'},
]
app.get('/api/members', (req, res) => {
res.json(members);
});
res.json sends JSON data. The response has ContentType set to application/json
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 202
ETag: W/"ca-3G6fuYk8sd6M9idwE8hMwBZh8g4"
Date: Fri, 04 Dec 2020 10:27:49 GMT
Connection: close
[
{
"id": 1,
"name": "John Doe",
"email": "jd@email.com",
"status": "a"
},
{
"id": 2,
"name": "John Doe Sr",
"email": "jd.sr@email.com",
"status": "a"
},
{
"id": 2,
"name": "John Doe Jr",
"email": "jd.jr@email.com",
"status": "a"
}
]
I am using VS Code REST Client (humao.rest-client) instead of Postman. I can store my API call samples together with the project files.
req
docs REQ
- https://expressjs.com/en/4x/api.html#req
- https://nodejs.org/api/http.html#http_class_http_incomingmessage
req.body
https://expressjs.com/en/4x/api.html#req
By default undefined, populated by using body-parsin middleware such as express.json or express.urlencoded()
- docs https://expressjs.com/en/5x/api.html#express.urlencoded
- https://expressjs.com/en/5x/api.html#express.json
moment
Should be replaced with a modern alternative.
I finished building the API functionality.
Next time, add view engine: