【问题标题】:Can't get Hello World with Node.js in Cloud9无法在 Cloud9 中使用 Node.js 获得 Hello World
【发布时间】:2020-06-16 09:46:52
【问题描述】:

我不知道如何让我的服务器响应 Hello World。 我什至不知道IP地址是什么。 ip是否列在我的终端选项卡上?

我刚刚使用默认的 Node.js 模板创建了一个 EC2 环境。 我需要提前设置更多的东西吗?

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

【问题讨论】:

    标签: node.js cloud9


    【解决方案1】:

    尝试下面的解决方案,如果您需要任何解释,请告诉我:

    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
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-02
      • 2021-02-21
      相关资源
      最近更新 更多