DeveloperBreeze

Simple RESTful API in Node.js using Express

javascript
// Import 'express' module
const express = require('express');
const app = express();

// Define a route for accessing a resource
app.get('/api/resource', (req, res) => {
  res.json({ message: 'Resource data' });
});

// Start the server and listen on port 3000
app.listen(3000, () => {
  console.log('RESTful API is running on port 3000');
});

Related Posts

More content you might like

Tutorial

Build a Custom Rate Limiter in Node.js with Redis

// redisClient.js
const redis = require("redis");

const client = redis.createClient({ url: process.env.REDIS_URL });

client.on("error", (err) => console.error("Redis error:", err));
client.connect();

module.exports = client;
// rateLimiter.js
const client = require("./redisClient");

const rateLimiter = (limit = 100, windowSec = 3600) => {
  return async (req, res, next) => {
    const ip = req.ip;
    const key = `rate_limit:${ip}`;

    const current = await client.get(key);

    if (current !== null && parseInt(current) >= limit) {
      return res.status(429).json({ error: "Too many requests. Try later." });
    }

    const multi = client.multi();
    multi.incr(key);
    if (!current) {
      multi.expire(key, windowSec);
    }
    await multi.exec();

    next();
  };
};

module.exports = rateLimiter;

Apr 04, 2025
Read More
Tutorial
go

Building a RESTful API with Go and Gorilla Mux

  • Setting up a Go project with Gorilla Mux.
  • Defining models and handling JSON data.
  • Implementing basic CRUD operations.
  • Testing the API using curl or Postman.
  • Implement authentication and authorization.
  • Add persistent storage using a database like PostgreSQL or MongoDB.
  • Explore more advanced routing and middleware options with Gorilla Mux.

Aug 12, 2024
Read More
Tutorial
javascript css +1

Building a Real-Time Chat Application with WebSockets in Node.js

npm install express socket.io

Create a file named server.js in your project directory and add the following:

Aug 03, 2024
Read More
Code
php

JWT Token Creation and Verification in Node.js using 'jsonwebtoken'

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!