0

I can't figure out how to get my server to respond with Hello World. I don't even know what IP address is. Is the ip listed on the tab of my terminal it?

I just created an EC2 environment with the default Node.js template. Do I need to setup more things beforehand?

https://i.stack.imgur.com/4m85x.png

sean
  • 1

1 Answers1

0

Try the solution bellow and let me know if you need any explanation:

const http = require("http");
const port = 3000; // make sure the port number is not used

const requestHandler = (req, res) => {   
    req.on('Error occurerd', (err) => {
        console.error(err);
        res.end();
    });
    res.end("Hello from AWS Cloud9!");
}

const server = http.createServer(requestHandler);

server.listen(port, () => {
    console.log(`Server is listening on port ${port}!`);
    // Run your script then copy past this url in your browser 127.0.0.1:3000
});
toh19
  • 1,083
  • 10
  • 21