How to Create HTML FILE with javascript [closed]

一世执手 提交于 2020-07-03 10:28:05

问题


I'm using website-scraper npm for scraper an website, https://github.com/website-scraper/node-website-scraper

I already got the Images from the website saved in assests folder. now I need to show the Images in a new dynamic html that this script need to create and to show this images. I saw this post: Create HTML file with JavaScript but its not seems to help.

How can I create an HTML using only JavaScript? create a real html File and save it locally. or should I use Nodejs? pass the images to server side and to attach the images to a hbs? Other options?


回答1:


You could use filesystem API to write anything you want to any file. You would create an HTML string using any method you want (string concatenation for example or using Underscore.js templates) and then write it to any file using the Node.js filesystem API.

var fs = require('fs');

var htmlContent = '<html>Whatever</html>';

fs.writeFile('/my-page.html', htmlContent, (error) => { /* handle error */ });


来源:https://stackoverflow.com/questions/52986777/how-to-create-html-file-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!