首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置NestJS应用程序接口应用程序的可执行文件

设置NestJS应用程序接口应用程序的可执行文件
EN

Stack Overflow用户
提问于 2019-02-17 01:56:59
回答 1查看 1.1K关注 0票数 0

我刚接触typescript和NPM,我已经用NestJS节点框架创建了一个API项目。我正在尝试通过捆绑我的应用程序来创建一个EXE文件。我已经尝试过Pkg exe creator和fuse-box。不过,我还是找不到任何可行的解决方案。请谁帮我把我的应用程序捆绑成一个exe文件。我已经在这个问题中附上了我的package.json。

`

代码语言:javascript
复制
{
  "name": "health-first",
  "version": "0.0.0",
  "description": "Meal management system",
  "author": "Dhayananth",
  "license": "MIT",
  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "nodemon",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rimraf dist && tsc",
    "start:prod": "node dist/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nestjs/common": "^5.4.0",
    "@nestjs/core": "^5.4.0",
    "@nestjs/typeorm": "^5.2.2",
    "mysql": "^2.16.0",
    "nestjs-flub": "^0.1.0",
    "reflect-metadata": "^0.1.12",
    "rimraf": "^2.6.2",
    "rxjs": "^6.2.2",
    "typeorm": "^0.2.11",
    "typescript": "^3.0.1"
  },
  "devDependencies": {
    "@nestjs/testing": "^5.1.0",
    "@types/express": "^4.16.0",
    "@types/jest": "^23.3.1",
    "@types/node": "^10.7.1",
    "@types/supertest": "^2.0.5",
    "fuse-box": "^3.7.1",
    "jest": "^23.5.0",
    "nodemon": "^1.18.3",
    "prettier": "^1.14.2",
    "supertest": "^3.1.0",
    "ts-jest": "^23.1.3",
    "ts-loader": "^4.4.2",
    "ts-node": "^7.0.1",
    "tsconfig-paths": "^3.5.0",
    "tslint": "5.11.0"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}

`

EN

回答 1

Stack Overflow用户

发布于 2019-02-18 18:30:00

不太确定为什么要从应用程序中创建一个exe文件?但我不是windows用户。在我的观点和经验中,我使用命令器或vorpal来创建使用嵌套容器的执行命令。

这是我使用的脚本示例

代码语言:javascript
复制
import { NestFactory } from '@nestjs/core';
import { TaskConsumer, JobConsumer, ConsumerModule } from './consumers';
import * as commander from 'commander';
const pack = require('./../package.json');
import { AppModule } from 'app.module';
import { ConsumerInterface } from 'consumers/consumer.interface';
import { Logger } from '@nestjs/common';

async function bootstrap(requestedConsumer: 'task' | 'job') {
  const app = await NestFactory.create(AppModule);

  await app.init();

  const consumer =
    requestedConsumer === 'task'
      ? app.select(ConsumerModule).get<ConsumerInterface>(TaskConsumer)
      : app.select(ConsumerModule).get<ConsumerInterface>(JobConsumer);

  await consumer.listen(requestedConsumer);
}

commander
  .version(pack.version)
  .command('run <consumer>')
  .action((requestedConsumer, cmd) => {
    if (requestedConsumer !== 'task' && requestedConsumer !== 'job') {
      Logger.warn(
        `Consumer [${requestedConsumer}] is not a valid consumer. Please enter 'task' or 'job'`,
        'Command',
      );
      process.exit();
    }

    bootstrap(requestedConsumer);
    process.stdin.resume();
  });

commander.parse(process.argv);

然后我在dev中运行这个脚本,就像ts-node -r tsconfig-paths/register src/queue.ts run task一样。然后在prod node dist/queue.js run task中。我可以加上一句但是..。老实说,...I不知道我为什么不这么做!

不确定这就是你要找的?但这就是我创建命令的方式,您可以在其中使用nestjs执行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54726035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档