gpt4 book ai didi

node.js - 修改示例 Hello World Node.js 代码在 Google Compute Engine 中未生效

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:21 25 4
gpt4 key购买 nike

我试图了解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;

最佳答案

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

关于node.js - 修改示例 Hello World Node.js 代码在 Google Compute Engine 中未生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39396497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com