Is there a really simple way to open a string containing html code in a browser using NodeJS? You can display basic html text in your browser by typing data:text/html,<html>Hello World!</html>
into the address bar. Also the open
module enables you to open an url by using open("https://example.com");
. But you can't do open("data:text/html,<html>Hello World;</html>");
since that does not seem to be forwarded to the browser.
Thanks in advance!
Since your last statement mentions sending it to the front end, I think what you're looking for is the ejs plugin.
npm i ejs --save. Instead of HTML files you're going to use.ejs files that are basically HTML with additional syntax.
Here is the npm page:
https://www.npmjs.com/package/ejs
Here's a decent tutorial:
https://medium.com/swlh/master-ejs-template-engine-with-node-js-and-expressjs-979cc22b69be
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.