简体   繁体   English

如何启动 Nestjs 应用程序

[英]How to start Nestjs application

I started working on a NestJS application, the previous developer did not leave any documentation or comments and I'm new to NestJS and Node generally.我开始开发一个 NestJS 应用程序,以前的开发人员没有留下任何文档或评论,而且我通常是 NestJS 和 Node 的新手。

I'm having a hard time running the application locally, the application was developed using the following technologies: NestJS, GraphQL, apollo-server-express, Prisma.我很难在本地运行该应用程序,该应用程序是使用以下技术开发的:NestJS、GraphQL、apollo-server-express、Prisma。

First, I extracted the repo files and run the following commands ( npm install , npm run build , npm run start ), I get the following error log:首先,我提取了 repo 文件并运行以下命令( npm installnpm run buildnpm run start ),我得到以下错误日志:

在此处输入图像描述

Here are my npm scripts:这是我的 npm 脚本:

    "build": "cross-env NODE_ENV=production webpack --progress --config webpack.config.prod.js",
    "start:hmr": "node ./dist/server.js",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",

I tried changing the start script to我尝试将启动脚本更改为

"start": "npm i -g @prisma/cli @nestjs/cli && prisma generate && node dist/main"

and still didn't work仍然没有工作

main.ts主要的.ts

import 'source-map-support/register';
import { Env } from '@shared/utils';
import { AppModule } from '@app/app.module';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter, NestExpressApplication } from '@nestjs/platform-express';
import { HttpExceptionFilter } from '@shared/filters/http-exception.filter';
import { LoggerService } from '@shared/services';
import './seed';

const LOGGER = new LoggerService('Main');
const PORT: number = Env('PORT', 3000);
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule, new ExpressAdapter(), {
    logger: LOGGER,
  });
  await app.useGlobalFilters(new HttpExceptionFilter()).listenAsync(PORT);
  return PORT;
}

bootstrap()
  .then(port => LOGGER.log(`🚀  Server ready at ${port}, started in ${process.uptime()}s`))
  .catch(e => LOGGER.error(e.message, e));

Note: I have both Nest cli and npm installed globally.注意:我在全球范围内安装了 Nest cli 和 npm。 Thank you in advance.先感谢您。

Try this way, replace your start command with this:试试这种方式,用这个替换你的启动命令:

"start": "nest start --watch , "start": "nest start --watch ,

First You need to add this in your package.json首先,您需要将其添加到 package.json
"start:dev": "nest start --watch"

Then you can try running the command然后你可以尝试运行命令
npm run start:dev

It will run the project in development mode.它将以开发模式运行项目。 You can also try deleting the ".spec" files in your project and running the above command.您也可以尝试删除项目中的“.spec”文件并运行上述命令。

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

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