Sunday, 5 July 2020

How to create a file in a specific path ?

Hi,I want to create a file in a subdirectory called pages. So I wrote this :```javascript const fs = require('fs');fs.writeFile(${__dirname}/pages/test.json, '', (err) => { if (err) console.log(err); }); ```But it throws an error : [Error: ENOENT: no such file or directory, open '/Users/.../Developer/pages/test.json'] { errno: -2, code: 'ENOENT', syscall: 'open', path: '/Users/.../Developer/pages/test.json' }As crazy as it seems I can't find a solution online. Any ideas ?Thanks.

Submitted July 05, 2020 at 12:40PM by to_fl

No comments:

Post a Comment