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:

Nx Adoption Guide: Overview, Examples, And Alternatives

Nx adoption guide: Overview, examples, and alternatives

Let’s explore Nx features, use cases, alternatives, and more to help you assess whether it’s the right tool for your needs.

Andrew Evans
Mar 28, 2024 ⋅ 9 min read
Understanding Security In React Native Applications

Understanding security in React Native applications

Explore the various security threats facing React Native mobile applications and how to mitigate them.

Wisdom Ekpotu
Mar 27, 2024 ⋅ 10 min read
Warp Adoption Guide: Overview, Examples, And Alternatives

warp adoption guide: Overview, examples, and alternatives

The warp web framework for Rust offers many enticing features. Let’s see when and why you should consider using warp in your projects.

Ukeje Goodness
Mar 26, 2024 ⋅ 8 min read
Integrating Next Js And Signalr For Enhanced Real Time Web App Capabilities

Integrating Next.js and SignalR to build real-time web apps

In this tutorial, you’ll learn how to integrate Next.js and SignalR to build an enhanced real-time web application.

Clara Ekekenta
Mar 25, 2024 ⋅ 8 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