I need to read a file on the server, parse it then load it in an array.
I installed peerlibrary:fs
and created a class like this:
ProvidersDictionary = function() {
var start = new Date().getTime();
this.providers = fs.readFileSync('/free-email-providers.txt').toString().split('\n');
this.lookUp = function(domain) {
return (this.providers.indexOf(domain) !== -1)? true : false;
}
}
free-email-providers.txt is in the /public folder, but can anywhere on the server. I keep having this error:
Error: ENOENT, open ‘/free-email-providers.txt’
Any ideas?
Any other easier way to do the same tasks?
[UPDATE]
Solved this using process.env.PWD :
this.providers = fs.readFileSync(process.env.PWD + ‘/server/dictionaries/free-email-providers.txt’).toString().split(’\n’);