使用 Node js 读取文件时出错

Error reading a file with Node js

我无法使用我在 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);
});

它给我的错误是:

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

什么可能导致此错误?

请交叉检查“./queries/anagconti_clienti_giorni.txt”文件的路径或权限。如果文件不存在,则在上述代码文件所在的同一级别创建 "queries" 文件夹。