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:

Rxjs Adoption Guide: Overview, Examples, And Alternatives

RxJS adoption guide: Overview, examples, and alternatives

Get to know RxJS features, benefits, and more to help you understand what it is, how it works, and why you should use it.

Emmanuel Odioko
Jul 26, 2024 ⋅ 13 min read
Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 ⋅ 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 ⋅ 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 ⋅ 5 min read
View all posts

22 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