learncodeacademy / node-tutorials

Node.js tutorials that accompany the Node.js video course
http://store.learncode.academy/
82 stars 40 forks source link

Es6 Destructing Syntax in lecture 9 routing #3

Closed danZib closed 8 years ago

danZib commented 8 years ago

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 {

willrstern commented 8 years ago

@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