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
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)