【问题标题】:Modifying sample Hello World Node.js code not taking effect in Google Compute Engine修改示例 Hello World Node.js 代码在 Google Compute Engine 中未生效
【发布时间】:2016-09-09 03:54:15
【问题描述】:

我正在尝试了解 Compute Engine 的工作机制,以便在 Node.js 中编写一个在 Compute Engine 中运行的 WebSocket。为了做到这一点,我首先开始运行(npm start)示例 Hello World 项目并让它工作。然后,我尝试将 ".send("Hello World!")" 更改为 ".send("Hello World2!")" 并再次运行,但我得到了 "Hello World!"再次,即使我更改了源代码。当我尝试“git commit”时,我得到“你的分支是最新的”。然后在尝试“git pull”和“git push”之后,我仍然得到“Hello World!”作为输出。如何修改代码并使其运行修改后的代码?

Google 提供的 Hello World 示例代码

var express = require('express');

var app = express();

// [START hello_world]
// Say hello!
app.get('/', function (req, res) {
  res.status(200).send('Hello, world!');
});
// [END hello_world]

if (module === require.main) {
  // [START server]
  // Start the server
  var server = app.listen(process.env.PORT || 8080, function () {
    var port = server.address().port;
    console.log('App listening on port %s', port);
  });
  // [END server]
}

module.exports = app;

【问题讨论】:

    标签: node.js git google-app-engine google-compute-engine google-cloud-platform


    【解决方案1】:

    您需要重新启动服务器才能使更改生效。更改 app.js 中的代码后,取消之前的“npm start”过程并再次调用它以运行更新后的服务器

    【讨论】:

    • 没想到这么简单 :) 谢谢!
    猜你喜欢
    • 2011-07-12
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    相关资源
    最近更新 更多