Reputation: 532
For some reason, I need to modify my mongodb with brute force. the expected data is in a file, and I need to update the mongodb's value by the read-out file stream. with node.js' help, I generate codes like this,
const fs = require('fs');
fs.open('./f.csv', 'r', (err, fd) => {
if(!err) {
fs.readFile('./server/f.csv', 'utf8', (err,data)=>{console.log(data);});
}
});
But, now I have a difficulty to find the file. the execution throws an error:
{ Error: ENOENT: no such file or directory, open './f.csv' errno: -2, code: 'ENOENT', syscall: 'open', path: './f.csv' }
I have tried to locate the file in the Meteor's public folder or server folder, which is also Meteor's backend, but the efforts are in vain. So how to make the codes find the file on Meteor's backend?
Any suggestion is welcome.
Upvotes: 3
Views: 84
Reputation: 5671
Easiest solution is to put the file in /private
and access it using the Assets
module:
https://docs.meteor.com/api/assets.html
Example: If you put the file in /private/f.csv
const data = Assets.getText('f.csv');
console.log(data)
// ... Do something with that data
Upvotes: 3