#Autoreload dev server when file ".env" is changed

24 messages · Page 1 of 1 (latest)

remote glade
#

Hi, is it somehow possible to configure Nest to watch file .env in development mode?

golden turret
#
ConfigModule.forRoot({
            isGlobal: true,
            envFilePath: [`${process.cwd()}${process.env.NODE_ENV === 'production' ? '\\envs\\prod.env' : '\\envs\\local.env'}`]
        }),

Something like that you can do with several envs, but Nest watch to .env on dev mode on default, read docs
https://docs.nestjs.com/techniques/configuration

remote glade
#

I think I didn't make myself clear.
I want the development mode to autoreload the server whenever the .env file is changed.

#

Autoreload dev server when file ".env" is changed

golden turret
#

I think it's not possible

#

but if it's possible i'm also under intrest 🙂

remote glade
#

With nodemon one can list every single file/directory to be watched.
I kind of wanted something like that.

golden turret
#

that's usefull, i also want to use it, if it's exists

#

today i must refresh several times manually 🙂

#

Hot Reload module in Nest, but i don't have time now to try it, if u find something intresting, let my know, if u can 🙂

remote glade
#

This is the Hot Reload of modules, without compiling all modules again.
Each module can me Hot Reloaded individually with Webpack.
I think the original problem would persist because .env is not part of any module.

golden turret
#

maybe you can use nodemon in the same script in package.json as run start:dev

#

nest --watch

#

u know nest start --watch nodemon ...

#

u try that?

remote glade
#

You mean to use nodemon as main process, encapsulating nest process?

#

And let only nodemon doing the watch thing?

golden turret
#

ye, nodemon watching only env files

#

but wait

#

nodemon don't reload modules in that case i think

remote glade
#

No, but it is, in theory, possible to make nodemon responsible to watch .env only, triggering a full reload of nest cli.
And let nest doing its own reload the way it is.

golden turret
#

i think about it exacly

remote glade
#

I won't try that now anyways.
I wanted a nest only solution 😆