emptygif
ভাষা: বাংলা

সব ভাষা ও ফ্রেমওয়ার্ক

Node.js standard library (node:http) JavaScript

Node.js standard library (node:http)-এর জন্য একটি JavaScript স্নিপেট, যা /pixel.gif-এ আসা রিকোয়েস্টের উত্তরে empty GIF পাঠায়। GIF-টি স্টার্টআপে একবারই ডিকোড হয়।

Node.js standard library (node:http) JavaScript

ফাইল
server.mjs
চালান
node server.mjs
import { createServer } from 'node:http';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

createServer((req, res) => {
  const { pathname } = new URL(req.url, 'http://localhost');
  if (req.method !== 'GET' || pathname !== '/pixel.gif') {
    res.writeHead(404).end();
    return;
  }
  res.writeHead(200, {
    'Content-Type': 'image/gif',
    'Content-Length': GIF.length,
    'Cache-Control': 'no-store',
  });
  res.end(GIF);
}).listen(8080);

আমরা এই স্নিপেট চালিয়েছি এবং এটি যে বাইটগুলো ফেরত দিয়েছে তা মিলিয়ে দেখেছি।

যাচাই করুন

curl -sI http://localhost:8080/pixel.gif

অফিশিয়াল সাইট: Node.js standard library (node:http)

JavaScript-এ আরও