2023-07-27
3590
#node
Geshan Manandhar
34779
Jul 27, 2023 ⋅ 12 min read

Build a REST API with Node.js, Express, and MySQL

Geshan Manandhar Geshan is a seasoned software engineer with more than a decade of software engineering experience. He has a keen interest in REST architecture, microservices, and cloud computing. He also blogs at geshan.com.np.

Recent posts:

Using Pavex For Rust Web Development

Using Pavex for Rust web development

The Pavex Rust web framework is an exciting project that provides high performance, great usability, and speed.

Ukeje Goodness
May 10, 2024 ⋅ 6 min read
Using The Resizeobserver Api In React For Responsive Designs

Using the ResizeObserver API in React for responsive designs

With ResizeObserver, you can build aesthetic React apps with responsive components that look and behave as you intend on any device.

Emmanuel Odioko
May 9, 2024 ⋅ 11 min read
Creating JavaScript Tables Using Tabulator

Creating JavaScript tables using Tabulator

Explore React Tabulator to create interactive JavaScript tables, easily integrating pagination, search functionality, and bulk data submission.

Emmanuel John
May 9, 2024 ⋅ 7 min read
How To Create Heatmaps In Javascript: Exploring The Heat Js Library

How to create heatmaps in JavaScript: The Heat.js library

This tutorial will explore the application of heatmaps in JavaScript projects, focusing on how to use the Heat.js library to generate them.

Oghenetega Denedo
May 8, 2024 ⋅ 7 min read
View all posts

20 Replies to "Build a REST API with Node.js, Express, and MySQL"

  1. async function create(newwSession){

    const result = await db.query(

    `INSERT INTO newsession
    (req_datettime )
    VALUES
    (? )`,
    [
    newwSession.req_datettime
    ]
    );
    can you please guide what i am missing i have created a new router and its says “message”: “Bind parameters must not contain undefined. To pass SQL NULL specify JS null”

    1. Found out that with MySQL 8.0.22+ the args need to be passed as a string. Changing the line in programmingLanguages.js from:

      `SELECT id, name, released_year, githut_rank, pypl_rank, tiobe_rank
      FROM programming_languages LIMIT ?,?`,
      [offset, config.listPerPage]

      to:

      `SELECT id, name, released_year, githut_rank, pypl_rank, tiobe_rank
      FROM programming_languages LIMIT ?,?`,
      [offset + “”, config.listPerPage + “”]

      Corrected this error.

  2. Hi, I am calling the API using axios in my react project but its showing 500 internal server error, I can’t figure why. Please Help

  3. Hello, Thank you so much for this perfect Tutorial ! I just have a question on get parts. I make a query to have some post with comments. But in the result I have one object for each comments (for all informations post +comment) . I would like to have the result like a tree. So 1 object per post which includes the 1 list of comments. Do you know how can I do ?

  4. When you are trying to do a POST request then the parameters that are strings needs to be wrapped with “”.

    So ${programmingLanguage.name} should be “${programmingLanguage.name}” 😊

    1. Thank you, I was getting an error while doing the POST request because of that: “Unknown column ‘dart’ in ‘field list'”. If anyone else encounters the same error, this is the reason why.

  5. Thank you for the tutorial. When creating the connection to de db, you commented “don’t expose password or any sensitive info”. Does that mean that there is another way to set the password for this connection? Could you please share how else to do it? Thanks very much.

  6. This tutorial is awesome, really assisted me to piece together something I needed to train on and I have never created my own API setup before, I always use mysql and nodejs for my own projects so this is the cherry for me, thanks a bunch, appreciated.

Leave a Reply