user1680104
user1680104

Reputation: 8887

How to work around node.js require caching in coffeescript?

I want to require a file, written in CoffeeScript in another file also written in CoffeeScript. I want want to require that file again when it changes (using fs.watch()), however as document module.require caches requires.

Is there an easy way to work around this?

Update:

This still doesn't seem to work:

fs.watch './file.coffee', (event, filename) ->
  delete require.cache[__dirname + '/' + filename]
  require './file'

Upvotes: 0

Views: 593

Answers (1)

Mustafa
Mustafa

Reputation: 10413

You can invalidate require cache:

require.cache#Object

Modules are cached in this object when they are required. By deleting a key value from this object, the next require will reload the module.

http://nodejs.org/docs/latest/api/globals.html#require.cache

Upvotes: 2

Related Questions