get lines as list from file node js

const fs = require('fs');

const readFileLines = (filePath) => {
  try {
    const fileContent = fs.readFileSync(filePath, 'utf-8');
    const lines = fileContent.split('\n').map(line => line.trim());
    return lines;
  } catch (error) {
    console.error('Error reading the file:', error.message);
    return [];
  }
};

const filePath = 'your_file.txt'; // Replace with the path to your file
const lines = readFileLines(filePath);
console.log(lines);