Last active
October 17, 2022 15:56
-
-
Save MrKotov/3690757b95ba93a8b79744f58b800b9b to your computer and use it in GitHub Desktop.
Hello world NodeJS Server
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 HOST = '127.0.0.1'; | |
const PORT = +process.argv[2] || 3001; | |
const server = http.createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'application/json' }); | |
res.end(JSON.stringify({ success: true, message: "Hello world!" })); | |
}) | |
server.listen(PORT, HOST).on('error', (err) => { | |
console.error(`Something went wrong: ${err}`); | |
}).on('listening', () => { | |
console.log(`"Hello World" Node Server running at http://${HOST}:${PORT}`); | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment