Oi tudo bom ? realizei o passo a passo porem depois do npm init o codigo parou de funcionar e apresenta o seguinte erro
node src/cli ./teste.txt node:internal/process/promises:289
triggerUncaughtException(err, true /* fromPromise */);
^
[Error: ENOENT: no such file or directory, open 'C:\Users\marce\OneDrive\Documents\Laneway\TERM 3 2024\new_project\node,react.js\undefined\result.txt'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\marce\\OneDrive\\Documents\\Laneway\\TERM 3 2024\\new_project\\node,react.js\\undefined\\result.txt'
}
Node.js v20.12.0
O codigo no momento esta dessa forma: codigo CLI
import fs from 'fs';
import trataErros from './errors/funcErr.js';
import { countWords } from './index.js';
const archiveWay = process.argv;
const link = archiveWay[2];
const direction = archiveWay[3];
fs.readFile(link, 'utf-8', (err, text) => {
try{
if (err) throw err
const result = countWords(text);
createAndSaveArchive(result, direction)
} catch(err){
trataErros(err);
}
});
async function createAndSaveArchive(listWords, direction){
const newArchive = `${direction}/result.txt`;
const textWords = JSON.stringify(listWords);
try{
await fs.promises.writeFile(newArchive, textWords);
console.log('archive created');
}catch(err){
throw err;
}
}
Codigo index.js
export function countWords(text){
const paragrafos = extractParagrafos(text);
const contagem = paragrafos.flatMap((paragrafo) => {
if (!paragrafo) return [];
return verifyDoubleWords(paragrafo);
})
return contagem
}
function extractParagrafos(text){
return text.toLowerCase().split('\n');
}
npm init:
{
"name": "node_react",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
npm install
{
"name": "node_react",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "node_react",
"version": "1.0.0",
"license": "ISC"
}
}
}
o erro fala que esta dando problema no promise da function await fs.promises.writeFile(newArchive, textWords);
vou tentar fazer mais umas aulas e ver se consigo concertar porem ainda tenho dificuldade em identificar os erros.