0

尝试将 express rest api 设置为 windows-service 我的服务总是在调用 url 时崩溃/停止。

在我的 package.json 之后:

{
  "name": "my-service",
  "version": "0.0.0",
  "description": "my-Service",
  "main": "server.js",
  "author": {
    "name": ""
  },
  "scripts": {
    "install": "node ./.bin/install.js",
    "uninstall": "node ./.bin/uninstall.js"
  },
  "dependencies": {
    "cypress": "^7.3.0",
    "dotenv": "^9.0.2",
    "express": "^4.17.1",
    "node-fetch": "^2.6.1",
    "node-windows": "^1.0.0-beta.5"
  }
}

这是我的 server.js

'use strict';
var port = process.env.PORT || 1337;
const express = require('express')
const app = express()
const dotenv = require('dotenv');
dotenv.config();

app.get('/', (req, res) => {
    res.send("Test");
});

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

最后是 install.js:

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
    name: 'Cypress-Service',
    description: 'my description',
    //script: './server.js',
    script: 'C:\\mypath\\server.js',
    stopparentfirst: false,
    nodeOptions: [
        '--harmony',
        '--max_old_space_size=8172'
    ]
    //, workingDirectory: '...'
    //, allowServiceLogon: true
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install', function () {
    svc.start();
});



svc.install();

heap out of memory我通过将 设置为 8172 修复了第一个错误--max_old_space_size。现在 Windows 服务启动了。但是调用localhost:1337服务会停止/崩溃server.js stopped running.

我怎样才能解决这个问题?

更新——固定

从安装脚本中删除nodeOption-part 一切似乎都有效。

4

0 回答 0