How to create a simple server in node js that returns hello world?



How to create a simple server in node js that returns hello world?..

Answer / Himanshu Singh

To create a simple server in Node.js that returns 'Hello World', you can use the http module. Here's an example: `const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn') }); server.listen(3000, () => console.log('Server running at http://localhost:3000/'));

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Node.js Interview Questions

What are JavaScript task runners?

1 Answers  


What template engines you can use with express?

1 Answers  


How to generate unique uuids/ guid in node js?

1 Answers  


Explain “Console” in Node.JS?

1 Answers  


Why is js single threaded?

1 Answers  


What is a Callback function in Node.js?

1 Answers  


What is environment variable in node js?

1 Answers  


What are the streams in node.js?

1 Answers  


Why is yarn better than npm?

1 Answers  


Write a simple code to enable cors in node js?

1 Answers  


What are the functionalities of npm in node.js?

1 Answers  


How node.js and javascript are related?

1 Answers  


Categories