Error in Reload, ts-Node-dev and Prismaclient

Asked

Viewed 104 times

2

Good afternoon my friends, all in peace?

I’m having to migrate a small API to Prisma by removing Typeorm. Well, so far I have been able to install and run smoothly, MAS (normal, kkkk). I noticed that when fiddling with a WHERE for example, I am required to restart Docker to test the change.

For example, your saving the code below will work smoothly and return the JSON:

import { Router } from 'express';
import { PrismaClient } from '@prisma/client';
// import { GetPriceListService } from '@services/commercial/price-lists/get';

const routes = Router();
routes.get('/:price_list_id/status', async (request, response) => {
  //
  const prisma = new PrismaClient();
  const result = await prisma.price_lists.findFirst({
    where: {
      id: request.params.price_list_id,
      // status: 'aaaaa',
    },
  });

  //
  return response.json(result);
});
export default routes;

But to add a new 'status' filter in WHERE, I save the file, I get the notification in the cosole that the memso has been changed:

backend | [INFO] 15:26:43 Restarting: /home/node/app/src/routes/commercial/price-lists/status.ts has been modified

but it doesn’t work, I have to reset the container, to apply the change.

my package.json start script, is like this:

"dev:server": "ts-node-dev --inspect --transpile-only --ignore node_modules -r tsconfig-paths/register src/server.ts"

From now on, thank you very much!!!

1 answer

2

Good morning,

I was able to figure out what was going on and resolve.

The moment I save the application, ts-Node-dev "kills" the child process and opens a new process. ts-Node-dev was not "killing" the process because Prisma creates another process (I believe it is the open connection to the database).

Solution

I added an event before starting the application to force the closure.

process.on('SIGTERM', () => {
  process.exit();
});

Thank you!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.