This is my project structure:
This is index.js
.
var express = require('express');
var router = express.Router();
var fs = require('fs');
var links = require('../models/Links');
var readline = require('linebyline');
var rl = readline('../data.txt');
router.get('/', function (req, res) {
rl.on('line', function (line, lineCount, byteCount) {
var data = line.split(',');
var id = data[0];
var url = data[1];
})
});
module.exports = router;
What am I doing wrong?
I tried rewriting
var rl = readline('/../data.txt');
var rl = readline(__dirname +'/../data.txt');
Nothing works.
To resolve the ENOENT warning message, you need to add a package. json file in the directory where you run the npm install command. And then run your npm install command again. This time, the warning message should not appear.
It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories. It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols. Follow this answer to receive notifications. edited Jun 4, 2019 at 14:30. community wiki.
The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.
Your readline invocation is still going to be relative to the directory your app is running in (your root, where app.js resides), so I don't think you need the parent directory reference.
It should be just
var rl = readline('./data.txt');
Or if you want to use __dirname
var rl = readline(__dirname + '/data.txt');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With