Chokidar Integration for .env File Monitoring in Effect Workflow

[SOLVED]

File Monitoring Question
I'm using chokidar to monitor
.env
file change, so the code restarts and check if there's a env variable missing (ConfigError).
It works.
I'm now just wondering where in my effect workflow should I add this task?

I have
const result = Effect.runFork(Layer.launch(AppLive))
result.addObserver((exit) => {
   if (Exit.isFailure(exit)) {
     Exit.mapError(exit, (error) => {
       if (ConfigError.isConfigError(error)) {
         if (ConfigError.isMissingData(error)) {
          console.log(`[Config Error] - Missing Data: ${error.message}`)
         }
       }
     })
   }
})

In the src/main.ts.

And below of it:

watch('./.env', {

}).on('change', async () => {
  const data = await Bun.file('./src/main.ts').text()
  Bun.write('./src/main.ts', data)
})


So can I just Layer.mergeAll the AppLive with a ConfigLive and put the chokidar code inside the ConfigLive in a Effect.gen?

๐Ÿ‘‹
Was this page helpful?