DEV Community

Discussion on: How To Build Rest API With NodeJS, Express, and MySQL

Collapse
 
juliest88 profile image
Julia Strichash • Edited

Hi,
This post shows just how to combine NodeJS with MYSQL in a simple way.
You can run whatever queries you want using the query async method (await query(sql, []))
Just don't forget the prepared statements if you have user input.

How to do it is another part of the SQL.

If you want to make a query that depends on another query,
all you need to do is write the first query with await query-> get the result,
Then use it on another query.

async-await it's a new feature from ES8, and it's like the newest version of Promise.

promise.then(data => {
    console.log(data);
});
Enter fullscreen mode Exit fullscreen mode

Is like:

const data = await promise();
console.log(data);
Enter fullscreen mode Exit fullscreen mode

The line below the await promise() is like using the .then() method.

You can read more about it to understand how to use it.

The utils.js file is just a file to hold the common functions that we can reuse over and over; that's all.