/    Sign up×
Community /Pin to ProfileBookmark

How to create an API in node.js and MySQL

Please help me to clear my first coding interview…I’m stuck… I am asked to create an API which will display a list of riders and total distance required for them to deliver the order. The list should be sorted based on shortest delivery distance to the highest with respect to the restaurant’s and rider’s location.

It has to be done using **node.js** and **MySQL only**…please help…..Ive attached the [link](https://drive.google.com/file/d/1bmABrDzrWqWDhiuHRxQ_b-UzwFsXP9Fz/view) to the provided MySQL file.

Each restaurant will have a delivery radius outside which the orders must not be accepted or delivered.
The riders within the restaurant’s delivery radius should only be considered for the response.

API Request: Restaurant ID & User coordinates.

API Response: List of Rider Names and total distance to deliver order to user

to post a comment

4 Comments(s)

Copy linkTweet thisAlerts:
@sibertMay 25.2022 — > @nicecoder#1644193 I am asked to create an API which will display a list of riders and total distance required for them to deliver the order. The list should be sorted based on shortest delivery distance to the highest with respect to the restaurant’s and rider’s location.

There is actually two tasks. First how to create the API and endpoints. And then how create the SQL query. But, I wonder what is the benefit of creating an API when you only need to query the database directly once? Or is there an existing API?
Copy linkTweet thisAlerts:
@LolaLoAug 02.2022 — In the database viewer, add a new database and name it api. Make sure MySQL is running or you will not be able to connect to the server context.

Once the api database is created, it will spawn a query to create a new table. With this query tools for sql SQL created a table structure with recommended users. Each user will have an identifier whose value is automatically incremented, a name and an email address. Set up routes that assume GET, POST approaches and where the paths and route parameter structure PUT . DELETE
Copy linkTweet thisAlerts:
@JimWickAug 08.2022 — Step 1 – Create Node JS Express App. Use the below command and create your express project with name expressfirst mkdir node-rest-crud-api.

Step 2 – Create Database and table For this App.

Step 3 – Connect App to database.

Step 4 – Create Rest Apis and Add in server.js.

Step 5 – Start Development Server.

Regards,

J Wick
Copy linkTweet thisAlerts:
@LolaLoAug 08.2022 — In the database viewer, add a new database and name it api. Make sure MySQL is running or you will not be able to connect to the server context.

Once the api database is created, it will spawn a query to create a new table. With this query [tools for sql](https://www.devart.com/dbforge/sql/sql-tools/) SQL created a table structure with recommended users. Each user will have an identifier whose value is automatically incremented, a name and an email address. Set up routes that assume GET, POST approaches and where the paths and route parameter structure PUT . DELETE
×

Success!

Help @nicecoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...