I am running Node.js with Express and am fairly new to the world of Javascript. I am trying to find a way of parsing a text file and outputting certain data from that file into a HTML table. I am able to open and read the file using fs.read and then output it to the console but I'm unsure of how to go about passing specific data from that string into table entries.
I'm not looking for someone else to write the code for me just some general advice and pointers would be really helpful to get me on my way.
Thanks!
Without additional code, I can't be any more specific than this. There may be other reasons you wouldn't want to do it this way. So I would first recommend being more specific in your questions.
I would say reading in the file and creating a string of the desired HTML table at server start time. So in your server.js file (or app.js or whatever file you run with node) you'd have something like this to read the file:
var fs = require('fs');
var express = require('express');
var app = express();
var htmlTable = '';
fs.readFile('/etc/passwd', function (err, data) {
if (err) {
throw err;
}
var parsedData = parseData(data);
htmlTable = createTable(parsedData);
});
app.get('/htmlTable', function(req, res){
res.send(htmlTable);
});
app.listen(3000);