Mi objetivo es cargar archivos ogg en node.js. Probé ReadFile pero me aparece este error: No se pudo leer el archivo. [Error: ENOENT: no existe tal archivo o directorio, abra 'Main\game\songs\test\Voices.ogg'] y el archivo existe.
Código:
fs.readdir('./game/songs', function(err, files){ if (err) { console.log("Could not list the directory.", err) return } files.forEach(function(file, index){ fs.readFile('./game/songs/'+file+"/Inst.ogg", function(err, data){ if (err) { console.log("Could not read file.", err) return } }) fs.readFile('./game/songs/'+file+"/Voices.ogg", function(err, data){ if (err) { console.log("Could not read file.", err) return } }) }) })Debe pasar la ruta absoluta del archivo, use la función join() del módulo de path incorporado:
const path = require('path'); const fs = require('fs'); fs.readFile(path.join(__dirname, 'YOUR_PATH_HERE'), function(err, data) {});