Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Conversation

nataliiazab
Copy link

@nataliiazab nataliiazab commented Apr 11, 2023

No description provided.

@nataliiazab
Copy link
Author

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?
  • What did you find hard?
  • What do you still not understand?
  • Any other notes?

@nataliiazab nataliiazab reopened this Apr 11, 2023
});

app.delete("/people", (request, response) => {
res.send("DELETE Request Called");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to try to use VSCode's code formatting function (press CMD/CTRL + P, then enter "> format" at the prompt box)

Are you deleting an element from the people array? Did you miss capturing the id from url?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for noticing - I've finished it now! Didn't know about CTRL + P + '> format', will learn more about this toll now. Thank you!

Comment on lines 22 to 23
app.listen(3000, () => {
console.log("listening on port 3000");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assign port number in a variable so you can refer to it in your console message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Jack, done :)

res.status(200).send({ messages: latestMessages });
});

app.put("/messages/:id", function (req, res) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if no message with the specified id is present? Also, what if the provided "id" is not an integer?

Copy link
Author

@nataliiazab nataliiazab Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, didn't think about it. Added if (messageIndex === -1) { return res.status(404).send({ error: "Message not found" });} and
if (isNaN(id)) {return res.status(400).send({ error: "Invalid ID" });}

Do you think it's a good way to address these issues, or is there a better way?

// const PORT = 9090;
// app.listen(process.env.PORT);

app.listen(9090, () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can listen to port specified by process.env.port when it is present or port 9090 by saying
app.listen( process.env.port || 9090,
Again, its better to use a variable to store the default port number 9090

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks for reviewing the code, Jack!!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont have definite answers to your question but just want to highlight the importance of

  1. Input validation
  2. Error handling
    I think Alun's material provided examples on the above aspects. You may take a look

@nataliiazab nataliiazab changed the title London Class 9 - Natalie Zablotska- Node - Week 2 London Class 9 - Natalie Z.- Node - Week 2 Apr 18, 2023
@nataliiazab nataliiazab changed the title London Class 9 - Natalie Z.- Node - Week 2 London Class 9 - Natalie Zablotska - Node - Week 2 Apr 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants