0

Is there a reason why this code doesn't work? additionally using node file.js responds MODULE_NOT_FOUND.

const fs = require('fs');

// Create the "text.txt" file with the content "hello world"
fs.writeFileSync('text.txt', 'hello world');

// Add additional text to the end of the file
fs.appendFileSync('text.txt', '\nThis is additional text.');

console.log('Hello, World!');
Kostas Minaidis
  • 4,681
  • 3
  • 17
  • 25
  • This code runs successfully. Is there any other code that you've missed to include in the sample? – Kostas Minaidis Feb 01 '23 at 10:50
  • How do you execute this code? – Kostas Minaidis Feb 01 '23 at 10:51
  • open terminal in vs code: node filename.js response: Error: Cannot find module '/path/filename.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15) at Module._load (node:internal/modules/cjs/loader:885:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } – user11140297 Feb 01 '23 at 10:58
  • You are probably in the wrong directory. Run this command from the directory that holds the filename.js file. – Kostas Minaidis Feb 01 '23 at 12:01

0 Answers0