回环nodejs服务器无法启动

问题描述 投票:0回答:1

我有一个nodejs loopback 3.x版本的项目,我最近转为nodejs的开发。我已经写好了模型和服务器方面的内容(server.js,serverroot.js)等。以下是依赖关系。

"dependencies" : {
    "@types/async": "2.0.40",
    "@types/lodash": "4.14.139",
    "@types/loopback": "3.1.3",
    "@types/loopback-boot": "2.23.0",
    "loopback-connector-rest": "3.0.0",
    "loopback-model-binder": "1.4.0",
    "@types/multiparty": "0.0.31",
    "rimraf": "2.6.1",
    "sinon": "3.2.1",
    "ts-node": "3.3.0",
    "typescript": "2.8.3",
    "gulp-sequence": "0.4.6",
    "gulp-symlink": "2.1.4",
    "gulp-typescript": "4.0.1",
    "request": "2.81.0",
    "shelljs": "0.8.1",
    "yargs": "11.0.0",
    "os-locale": "3.1.0",
    "loopback-connector": "4.4.0",
    "strong-globalize": "2.10.0",
    "strong-remoting": "3.14.0"
}

这是我在server.ts中的代码片段。

const app: any = loopback();

boot(app, __dirname, (err) => {
   if (err) throw err;
});

app.start = () => {
    return app.listen(() => {
        const BASE_URL = app.get('url').replace(/\/$/, '');
        const explorer = app.get('loopback-component-explorer');
        if (explorer) {
            Logger.info(`Browse your REST API at ${BASE_URL}${explorer.mountPath}`);
        }
    });
};

以下是安装和启动应用程序的步骤。

  • npm安装
  • npm运行构建
  • npm运行开始

但应用程序没有启动,没有错误,但在命令提示下返回。. 我启用了 npm run start -verbose 命令,我发现了以下内容。

loopback:datasource Module ./connectors/rest not found, will try another candidate. +10ms loopback:datasource Initializing connector RequestBuilder +561ms loopback:datasource Connector is initialized for dataSource rest +7ms loopback:datasource DataSource rest is now connected to undefined +1ms lifecycle [email protected]~start: unsafe-perm in lifecycle true

请告诉我关于上述问题的任何提示。

node.js rest loopbackjs nodejs-server
1个回答
1
投票

这是我的一个愚蠢的失误。一旦你创建了应用程序,然后在启动过程中你需要启动应用程序。

boot(app, __dirname, (err) => {
    if (err) throw err;
    app.start(); // <-- Fix
});
© www.soinside.com 2019 - 2024. All rights reserved.