Lessons Learned #2

Aug 10, 2017

New project, should I use ES 6 or ES 5.1?

So, despite all the red showing that ES 6 isn't supported by older browsers 
Like here: or here or here. I decided to go with ES6 for a new project. 

I mean, ES5 was standardized in 2009. 8 years ago. According to Moore's law, that's like 6 generations, or roughly the equivalent of 120 human years. Best not to start with something that ancient!  I'm going with ES 6. 

Sigh ... well, one drawback is that my muscle memory types 'var' when now I guess I should be using 'let' ...😆

More promises and better ways

I've got a lot to learn. But I found this, it was clear and easy to understand. Kudos to the folks at Tao of Code

Requiring and importing code ... yeah parentheses matter!


I started with this
database.js
module.exports.database = function () {
    return mysql.createPool(config.database);};

And used it like this
let Database = require ('./database').database();

But I don't like the .database(); on the end.
To fix that, I changed it to this

database.js
module.exports = function () {
    return mysql.createPool(config.database);}();

And use it like this.
let Database = require ('./database');

Little things, but those parentheses really matter. I had to make sure to export the results of the executed function, not the function...

No comments:

Post a Comment

XAMPP phpMyAdmin subdomain on localhost

Create a localhost subdomain for phpMyAdmin on XAMPP Open xampp\apache\conf\extra\http-vhosts.conf and append the following (modify the Docu...