Home > front end >  How do I use node.js on a localhost:8000 server?
How do I use node.js on a localhost:8000 server?

Time:07-23

I have some pure JS code and HTML and CSS on my localhost:8000 server. I have installed node.js and I am able to use it without problem testing it on the VS code terminal. However, I want to integrate the file reading mechanic of node.js into the code that I am running on the localhost:8000 server. I want to put this node.js code into my webpage on localhost:8000

const {readFileSync, promises: fsPromises} = require('fs');
function syncReadFile(filename) {
const contents = readFileSync(filename, 'utf-8');

const arr = contents.split(/\r?\n/);

console.log(arr); //            
  • Related