Node.js 8 LTS

SKGNodejs Meetup - http://kostasbariotis.com

Node.js Release Plan

SKGNodejs Meetup

Node.js 8 Honorable Changes

  • V8 JavaScript Engine 6.1(Link)
  • HTTP/2 API without a flag (Link)
  • Node.js Native Addons API (N-API) (Link)
  • More ES7 support
    • Async/Await
    • Object.values/entries
    • Trailing commas in parameters

SKGNodejs Meetup

Async Functions

SKGNodejs Meetup

async function loginController(req, res, next) {
  const { email, password } = req.email;

  try {
    if (!email || !password) {
      throw new WrongCredentialsError();
    }

    const user = await fetchUserByEmail(email);

    if (user.password !== hashPassword(req.password)) {
      throw new WrongCredentialsError();
    }

    await markLoggedInTimestamp(user.userId);
    await sendEmail(user.userId);

    const token = await generateJWT(user);

    res.json({ success: true, token });

  } catch (err) {
    if (err instanceof WrongCredentialsError) {
      res.json({ success: false, error: 'Invalid email and/or password' })
    } else if (err instanceof DBConnectionError || err instanceof EmailError) {
      res.json({ success: false, error: 'Unexpected error, please try again' });
    } else {
      res.json({ success: false })
    }
  }
}

SKGNodejs Meetup

Object values/entries

const object = {
  file: 'name',
}

console.log('Object.keys :', Object.keys(object))
console.log('Object.values :', Object.values(object))
console.log('Object.entries :', Object.entries(object))

// Object.keys : [ 'file' ]
// Object.values : [ 'name' ]
// Object.entries : [ [ 'file', 'name' ] ]

SKGNodejs Meetup

Trailing commas

function exec(param1, param2) {
  return `${param1}, ${param2}`;
}

function exec(param1, param2,) {
  return `${param1}, ${param2}`;
}

function exec(
  param1, 
  param2,
) {
  return `${param1}, ${param2}`;
}

SKGNodejs Meetup

That's all basically, thank you for your time. I know I wasn't supposed to put long text on my slides but what the heck? Who make the rules? Those are my slides and I can do whatever I want. Is that ok with you? Well guess what? I don't even car.

SKGNodejs Meetup

Made with Slides.com