AshKeys

Confessions and Confusions of a Freelance Fullstacker.

Ashok Mannolu Arunachalam, nodejsAPIexpressjs
Back

API Development with Node.js and Express

In my previous post, we talked about how to run a webserver by using only node modules. As mentioned before, express is good when it comes to routing. Now, we can talk bit more in detail about the API development around it. Express makes the API development looks easy as it takes care of the uneasy parts and let us only worry about the APIs.

For instance, to build get endpoint you just have to do the following:

js
const express = require('express');
const app = express();
app.get('/api/greet', function (req, res) {
res.send('Hello, Welcome to AshKeys!');
});
app.listen(3000, () =>
console.log("API is up and running at http://localhost:3000");
);

When you hit the endpoint localhost:3000/api/greet, you see the Hello, Welcome to AshKeys! message being displayed.

Congratulations! You have created your first API with express.

We can use other HTTP request methods such as post, put, delete, merge, patch and various others. You can see a full list of potential routing methods here: Express routing methods