Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Node.js

Create API and Testing in Node.js

Build a simple JSON API with routing by URL/method and test it in the browser or Postman.

Create API and Testing in Node.js — a practical guide to create Node.js API with clear examples you can reuse in real projects.

Create API and Testing in Node.js — 24/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.

Short description

A basic API inspects `req.url` and `req.method`, then returns JSON. Test endpoints with Postman, Thunder Client, curl, or the browser for GET.

Tiny JSON API

const http = require('http');

http.createServer((req, res) => {
  if (req.url === '/api/health' && req.method === 'GET') {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    return res.end(JSON.stringify({ status: 'ok' }));
  }
  res.writeHead(404, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ error: 'Not found' }));
}).listen(3000);

Leave a reply

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