简体   繁体   English

将简单的 Node.js express 服务器打包成 Windows 中的独立可执行文件时出现问题

[英]Problem packaging a simple Node.js express server into standalone executable in Windows

As a test I prepared this simple index.js作为测试,我准备了这个简单的 index.js

var express = require('express')
var app = express()
var port = process.env.PORT || 1337;
var httpServer = require("http").createServer(app);

app.get('/', function (req, res) {
  res.send('hello world')
})

httpServer.listen(port, function() {
    console.log("Server running on port " + port + ".");
});

Then I try to package this server as a standalone Windows executable:然后我尝试将此服务器打包为独立的 Windows 可执行文件:

pkg index.js -t node10-win-x64

Using command prompt in Windows, I type "index.exe" in the folder with index.exe.在 Windows 中使用命令提示符,我在带有 index.exe 的文件夹中键入“index.exe”。 I do not see the console log at all.我根本看不到控制台日志。

Visiting http://localhost:1337 in browser also failed to see anything.在浏览器中访问http://localhost:1337也没有看到任何东西。

Why?为什么?

您能否在 index.exe 文件所在位置的命令提示符中尝试以下命令:

index.exe index.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM