All Demos

How do I build a REST API with Node.js?

G

Here's a quick guide to building a REST API with Express.js:

1. Setup

npm init -y

npm install express

2. Create your server

const express = require('express');

const app = express();

app.use(express.json());

let items = [

{ id: 1, name: 'Item One' },

{ id: 2, name: 'Item Two' },

];

app.get('/api/items', (req, res) => {

res.json(items);

});

app.post('/api/items', (req, res) => {

const item = { id: items.length + 1, ...req.body };

items.push(item);

res.status(201).json(item);

});

app.listen(3000, () => console.log('Running on :3000'));

Key principles:

  • Use proper HTTP methods (GET, POST, PUT, DELETE)
  • Return appropriate status codes
  • Validate input data
  • Handle errors gracefully
  • View Prompt

    Create a polished AI chat interface similar to ChatGPT. Include: a sidebar with conversation history, a main chat area with message bubbles (user on right, assistant on left), a text input with send button at the bottom, markdown rendering in assistant messages with code blocks, typing indicator animation, and a model selector dropdown. Use the Gumroad design system with cream background, black borders, pill-shaped buttons. No shadows, no gradients.

    Built with GPT-5.3