Why is node.js "filehandle.readLines()" giving me "TypeError: console.log(...) is not a function"?

53 Views Asked by At

I'm trying to learn about how Node works with files, and going through the filesystem docs.

Currently I'm trying to use the filehandle.readLines() method but am hitting a brick wall and it's driving me mad!

The problem is that, any time I try to console.log within the function that calls readLines() I get the following error:

TypeError: console.log(...) is not a function

I started with my own code, but have now reached the point of copying the code in the Node docs, but the error persists. Here is the current iteration:

const fs = require("fs");
const { open } = require ("node:fs/promises");


async () => {
    const file = await open("/Users/max/Documents/node-fs-fun/input.txt");

    for await (const line of file.readLines()) {
      console.log(line);
    }
  })();

Any insight would be greatly appreciated!

I've tried putting the console.log elsewhere within the function and I get the same result.

I am expecting each line of the target file to be logged to the console, but instead I'm just getting the same error over and over again: TypeError: console.log(...) is not a function

0

There are 0 best solutions below