Mr X
Mr X

Reputation: 129

Error reading a file with Node js

I can't read a file with this code that I've found on internet...

var express = require('express');
var app = express();
var fs = require('fs');
var port = 8080;

app.get('/', function(req, res) {
  fs.readFile('./queries/anagconti_clienti_giorni.txt', 'utf8', function(err, data) {
    if (err) {
      res.send(err);
    } else {
      res.send(data);
    }
  });
});

var server = app.listen(port, function() {
  console.log("Started on http://localhost:" + port);
});

The error that it give to me is:

{
"errno":-4058,
"code":"ENOENT",
"syscall":"open",
"path":"C:\Users\AlessandroGolin\Desktop\Mia\Visual_Studio\server_link\queries\anagconti_clienti_giorni.txt
"}

What could be causing this error??

Upvotes: 1

Views: 1286

Answers (1)

Mahesh Patil
Mahesh Patil

Reputation: 76

Please cross check the path or permission of "./queries/anagconti_clienti_giorni.txt" file. If file not exist then create your "queries" folder at same level where your above code file exist.

Upvotes: 1

Related Questions