Skip to content

Instantly share code, notes, and snippets.

@ahmetcanisik
Created March 16, 2025 12:43
Show Gist options
  • Save ahmetcanisik/9fd2fd24c1ffe1232e515e383a78736f to your computer and use it in GitHub Desktop.
Save ahmetcanisik/9fd2fd24c1ffe1232e515e383a78736f to your computer and use it in GitHub Desktop.
basic node.js server
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