Nestjs compilation not reflecting changes

Viewed 415

Problem

I'm creating a Nest.js based app and until now everything went just fine. After changing the connection approach (using the `@nestjs/mongoose` package) from snippet1 to snippet2 below, the running app didn't reflect changes. It keeps connecting via a connection string that doesn't appear anywhere in the codebase.

snippet1

imports: [
    MongooseModule.forRoot(config.db.uri, { useFindAndModify: false }),
    /* other imports */
  ],

snippet2

 imports: [
    MongooseModule.forRoot(config.db.uri, {
      connectionFactory: (connection) => {
        connection.plugin(accessibleRecordsPlugin);
        return connection;
      },
      dbName: isInDevelomentMode(process.env.NODE_ENV) ? 'dev' : 'prod'
    }), 
    /* other imports */ 
]

Regardless of the snippets above, even by updating only the JSON file containing the constant, the changes are not reflected and the app keeps connecting to the old one.

I read the string from the config.json file as following

import * as config                 from './config/config.json';
"db": {
    "uri": "mongodb+srv://revo:<psw>@cluster0.ngr5j.mongodb.net/?retryWrites=true&w=majority",
    "defaultUpdateOptions": {
      "new": true
    }
  }

What I've tried

  • Deleting dist folder then re-running npm run start:dev
  • Deleting node_modules folder then re-running npm i and npm run start:dev
  • Running the app via npm run build && npm run start as mentioned in Nest.Js not accepting any changes

Current workaround

At the moment, the only thing that allowed me to update the connection string in the running app was to push my code to a remote git repository, deleting all the local files, pulling the code back again and re-running the whole installation and running process.
0 Answers
Related