【发布时间】:2020-06-16 09:46:52
【问题描述】:
我不知道如何让我的服务器响应 Hello World。 我什至不知道IP地址是什么。 ip是否列在我的终端选项卡上?
我刚刚使用默认的 Node.js 模板创建了一个 EC2 环境。 我需要提前设置更多的东西吗?
【问题讨论】:
我不知道如何让我的服务器响应 Hello World。 我什至不知道IP地址是什么。 ip是否列在我的终端选项卡上?
我刚刚使用默认的 Node.js 模板创建了一个 EC2 环境。 我需要提前设置更多的东西吗?
【问题讨论】:
尝试下面的解决方案,如果您需要任何解释,请告诉我:
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
});
【讨论】: