learncodeacademy/node-tutorials

Es6 Destructing Syntax in lecture 9 routing

Closed this issue · 1 comments

Hi Will,
First of all thanks for all the great Tutorial and everything really.

Quick question about the destructive id assignment in users.js

  .get("/:id", (req, res) => {
    const { id } = req.params;
    const user = users.find(user => user.id == id);

    if (user) {
      res.send(user);
    } else {
      res.status(404).send(`User ${id} does not exist`);
    }
  })

I'm using nodejs version 4.5 , but somehow when trying to use the node command here I always end up with an error message. Do you maybe know why?

const { id } = req.params;
      ^

SyntaxError: Unexpected token {

@danZib Great to hear you're finding the course helpful!
So yes, ES6 destructuring didn't make it in until Node v6, which is what I'm using for the video tutorials.
http://node.green/#destructuring--declarations