在 Node.js 中创建 HTTP 服务器时的 Windows 安全警报

标签 windows node.js

我正在使用 node.js 创建一个 HTTP 服务器,它工作正常但是在任何 Node 应用程序第一次运行时,Windows 安全防火墙会中断我的应用程序。我希望这个安全警报不应该显示,我有检查了很多引用资料,但没有找到我的答案。

这是我的代码:

var http = require('http');
var PORT = process.env.PORT || 3000;

http.createServer(function (req, res) {
  console.log('%d request received', process.pid);
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello world!\n');
}).listen(PORT);

console.log('%d listening on %d', process.pid, PORT);

最佳答案

允许通过 Windows 防火墙访问该应用程序:

  • Go to: "Control Panel > System Ecurity > Windows Firewall > Advanced Settings".
  • Create new rule.
  • Select "Port" and press "Next".
  • Allow TCP and port your are attempting to expose (default 3000, you might want to expose 80), and press "Next".
  • Select "Allow the connection" and press "Next".
  • Check all: Domain, Private, Public and press "Next".

Source

我还建议您更换:

var PORT = process.env.PORT || 3000;

与:

var PORT = 3000;

关于在 Node.js 中创建 HTTP 服务器时的 Windows 安全警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971846/

相关文章:

c++ - WinAPI 函数 Hook 以捕获网络

javascript - 递归目录搜索,包括 ZIP 和 RAR 内的文件

node.js - 为预安装运行的 npm 脚本,但不为预更新运行

javascript - Discord Bot "Status"从播放到观看?

windows - Windows 驱动程序签名的复杂性(重命名和重新签名 OpenVPN tap 驱动程序)

c++ - CreateWindow 函数不起作用。Visual Studio 2015

c++ - 函数 CWnd::CreateControl 成功,但 m_hWnd 为 NULL

vb.net - 如何一次执行四个查询然后检查成功或失败?

javascript - 使用 node.js 和 pdf.js 将 pdf 转换为 html 文件

node.js - 如何检查heroku上的错误日志? (nodejs应用程序)