I tried to add some custom functions into the FS module of NodeJS, this module is part of NodeJS' core programs. I found the corresponding file (fs.js) in the following location: /usr/lib/nodejs. The problem was that the changes that I've made seemed to not affect anything when the corresponding module and function was called.
What I did was I added a function like this in /usr/lib/nodejs/fs.js:
fs.someRandomFunc = function(){return 'Yeah!'}
However, when I called the function, it replied :
var fs = require('fs')
console.log(fs.someRandomFunc())
// Error Message
TypeError: Object #<Object> has no method 'someRandomFunc'
By the way, this also happens to the other core modules, such as module.js and path.js. Does this happen because NodeJS caches the core JS program instead of loading it from /usr/lib/nodejs?
Any idea to resolve this issue would be appreciated.
Thanks!
fs is part of NodeJS' Core Modules. As such, it is compiled into binary and distributed. So modifying the source is not going to take effect unless you recompile them.
It is anyway not a good idea to modify Node's source files directly. What you can/should instead is extend the existing fs module with your own functions, like graceful-fs does, or replace it entirely with your version, like fs-extra does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With