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:

Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 ⋅ 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 ⋅ 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 ⋅ 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 ⋅ 10 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