emptygif
ਭਾਸ਼ਾ: ਪੰਜਾਬੀ

ਸਾਰੀਆਂ ਭਾਸ਼ਾਵਾਂ ਅਤੇ ਫਰੇਮਵਰਕ

Node.js standard library (node:http) JavaScript

Node.js standard library (node:http) ਲਈ JavaScript ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ 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 ਵਿੱਚ ਹੋਰ