4

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.

I'm having a hard time running the application locally, the application was developed using the following technologies: 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:

enter image description here

Here are my npm scripts:

    "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

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. Thank you in advance.

Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
Suhilah Salam
  • 51
  • 1
  • 4

2 Answers2

2

Try this way, replace your start command with this :

"start": "nest start --watch,

Denny Danu
  • 61
  • 2
0

First You need to add this in your 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.

Afaq Shah
  • 307
  • 2
  • 6