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 React Shepherd To Build A Site Tour

Using React Shepherd to build a site tour

React Shepherd stands out as a site tour library due to its elegant UI and out-of-the-box, easy-to-use React Context implementation.

Onuorah Bonaventure
May 1, 2024 ⋅ 14 min read
A Guide To Cookies In Next Js

A guide to cookies in Next.js

Cookies are crucial to web development. This article will explore how to handle cookies in your Next.js applications.

Georgey V B
Apr 30, 2024 ⋅ 10 min read
Handling Dates In JavaScript With Tempo

Handling dates in JavaScript with Tempo

Use the Tempo library to format dates and times in JavaScript while accounting for time zones, daylight saying time, and date internationalization.

Amazing Enyichi Agu
Apr 30, 2024 ⋅ 8 min read
A Guide To Deno.cron

A guide to Deno.cron

This guide explores how to use the cron package in Deno, `Deno.cron`, to handle scheduling tasks with specific commands.

Rosario De Chiara
Apr 29, 2024 ⋅ 5 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