Build NodeJS API step by step with Express MySQL

Build NodeJS API step by step with Express MySQL
Spread the love

We want to discuss that how can build NodeJS API step by step with Express MySQL NodeJS API step by step with Express MySQL Nodejs is one of most valuable framework for development application very fast and Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the Chrome V8 engine and executes JavaScript code outside a web browser. First of all we need to understand that what is NodeJS and process

Below we can understand that how to create NodeJS API(Application programming interface) using express and MySQL

So here we have question in our mind that what is API and how it is work for creating an application

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. Each time you use an app like Facebook, send an instant message, or check the weather on your phone, you’re using an API

Steps to create API in NodeJS using Express and MySQL

  • Create directory of NodeJS API
  • Open command prompt
  • Root folder type npm (Node package manager) init
  • Press enter enter till init process complete
  • Type code . means open project in Visual studio code
  • Open project. json file
  • Need to install some dependencies
  • Open command prompt and install npm install express MySQL body-parser
  • After Installation of node modules and dependencies
  • After that when install successfully then we have to install nodemon npm so that when i change on project then changes will reflect automatically

  • Run command npm install –save-dav nodemon
  • Start npm using command npm start
  • Open app.js and write some lines of code that means define required things

const express = require(‘express’)
const bodyParser = require(‘body-parser’)
const mysql = require(‘mysql’)

  • In app.js Those two lines are most important line we can define port here

const app = express()
const port = process.env.PORT || 5000;

  • After that in app.js file parse some json data we need to add two lines

app.use(bodyParser.urlencoded({ extended: false }))

  • Then Write MySQL code like shown below

// MySQL Code goes here

  • Listen on environment port or 5000

app.listen(port, () => console.log(Listening on port ${port}))

  • After that disconnect server then start server again
  • Open Browser and type url http://localhost:5000 press enter you can see that its working fine

Download postman app to api testing
so now we are going to create api
you can find link below
Make Button(

  • For MySQL we have to start xampp control and open browser
  • write http://localhost/phpmyadmin
  • Go to phpmyadmin and create database so that you can access your database tables and many more things
  • Just Create New Table name whatever you want

When your table created successfully then insert some data in table

  • Let we start to write code of MySQL connection
  • Get all data from table write some code like this
  • once your code complete then http://localhost:5000
  • Now you can test your api using postman

So this is the api the explanation of Nodejs with express and MySQL with nodemon i hope this information will help a lot thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *