We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Carmelo • 4 years ago

Hi Scott, what about remote video file instead of a static file?

Tahor Sui Juris • 5 years ago

Excellent post!

Question please:

Why does this only return the first character of the string?
const searchkeywords = fs.readFileSync('kwords.csv','utf-8');
for (let kword of searchkeywords) {
console.log(`Search Keyword: ${kword}`);

Text for the first 10 rows is:

1-800-FLOWERS.COM, INC.
1ST SOURCE
1ST SOURCE CORP
3D SYSTEMS
8X8, INC.
A.H. BELO
AAON
AARON RENTS
ABERCROMBIE & FITCH
ABIOMED

Scott • 5 years ago

I haven't actually tested this out myself, but my guess is it's because of how you're reading the file. Looks like you're reading it all as one string instead of one line per item. Try reading the file as shown in this article and then iterating through that list: https://stackabuse.com/read-a-file-line-by-line-in-python/

Shankar Singh Rajput • 5 years ago

I'm using pdfreader to read pdf files
var fs = require("fs");
var PdfReader = require('pdfreader').PdfReader;
fs.readFile("E://file streaming in node js//demo//read.pdf", (err, pdfBuffer) => {
console.log(pdfBuffer);
// pdfBuffer contains the file content
new PdfReader().parseBuffer(pdfBuffer, function(err, item){
if (err)
callback(err);
else if (!item)
callback();
else if (item.text)
console.log(item.text);
});
});

every time i got error, can't find module file

Scott • 5 years ago

Which module can it not find? Do you have `pdfreader` installed? If not, you should first install it via npm with `npm install --save pdfreader`. Hopefully this helps!

Jeff Cubinski • 5 years ago

Hey Scott thanks for this! Great info.

Have a question - I need to read an external CSV file into a nodeJS program. The file resides on an external server so i want to read it from there and I need to read it row by row. How could that be done? Thanks!

Scott • 5 years ago

Hi Jeff! If it is on a server there are a few ways you can retrieve it. I've used the Node.js package "scp2" and had good success using that to download files via SCP. You could do the same with FTP or HTTP if it's a public file. Your first step is to find a method to download the file locally and then read it using the steps outlined in this article. Hope that helps!