Created
May 3, 2024 08:25
-
-
Save shubhamp-sf/0af7c6b46482f6787b730f3197cec874 to your computer and use it in GitHub Desktop.
Interview Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require("http"); | |
const url = require("url"); | |
const server = http.createServer((req, res) => { | |
const parsedUrl = url.parse(req.url, true); | |
const path = parsedUrl.pathname; | |
const query = parsedUrl.query; | |
const numberOfImagesRequest = query.count; | |
if (path === "/images") { | |
if (req.method === "GET") { | |
console.time("/images"); | |
const imageUrls = []; | |
// Write your code here... | |
console.timeEnd("/images"); | |
res.statusCode = 200; | |
res.setHeader("Content-Type", "application/json"); | |
res.end(JSON.stringify(imageUrls)); | |
} else { | |
res.statusCode = 405; | |
res.setHeader("Allow", "GET"); | |
res.end("Method Not Allowed"); | |
} | |
} else { | |
res.statusCode = 404; | |
res.end("Not Found"); | |
} | |
}); | |
const port = 3000; | |
server.listen(port, () => { | |
console.log(`Server running at http://localhost:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment