Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

render a full web page in node.js code

Tags:

html

node.js

I am running a node.js server, and it is rendering a web page wonderfully. When I look at this in a browser, it runs exactly as I expect.

However, what I actually want to do is make the call to fully generate the html page - exactly as it is in the browser - within the node.js code, as a call. Currently, I have tried this:

http.request("http://localhost:8000/").end();

(with a few variants). This does exactly what it says, which is to make the single call to the server for the page - what it doesn't do is actually render the page, pulling in all of the other script files, and running the code on the page.

I have tried exploring express and ejs, and I think I need to use one of these, but I cannot find out how to do this fairly straightforward task. All it needs is to render an html page, but it seems to be a whole lot more complex than it should be.

like image 840
Schroedingers Cat Avatar asked May 13 '26 10:05

Schroedingers Cat


1 Answers

What output do you want? A string of HTML? Maybe you want PhantomJS the headless browser. You could use it to render the page, then get the rendered DOM as a string of HTML.

like image 144
Trevor Dixon Avatar answered May 15 '26 00:05

Trevor Dixon