Created
March 16, 2025 12:43
-
-
Save ahmetcanisik/9fd2fd24c1ffe1232e515e383a78736f to your computer and use it in GitHub Desktop.
basic node.js server
This file contains hidden or 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 server = http.createServer((req, res) => { | |
const urlPath = req.url; | |
if (urlPath === "/overview") { | |
res.end('Welcome to the "overview page" of the nginX project'); | |
} else if (urlPath === "/api") { | |
res.writeHead(200, { "Content-Type": "application/json" }); | |
res.end( | |
JSON.stringify({ | |
product_id: "xyz12u3", | |
product_name: "NginX injector", | |
}) | |
); | |
} else { | |
res.end("Successfully started a server"); | |
} | |
}); | |
server.listen(3000, "localhost", () => { | |
console.log("Listening for request"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment