简体   繁体   English

如何使用 expressjs 写入 HTML 文件

[英]How do I write to an HTML file using expressjs

Ok, this sounds crazy, but let me explain.好的,这听起来很疯狂,但让我解释一下。 I want a user to be able to push a button, and then the html file is edited in such a way that it a NEW p element is created, and stays there PERMENENTLY (eg on reload and for EVERYONE to see).我希望用户能够按下一个按钮,然后编辑 html 文件,以便创建一个新的 p 元素,并永久保留在那里(例如重新加载并让每个人都看到)。 Any way on how I could do that.关于我如何做到这一点的任何方式。

Again I am using node.js/express, and html/js/css.我再次使用 node.js/express 和 html/js/css。

It really depends upon exactly what you're doing.这真的取决于你在做什么。

Conceptually, you would probably use some sort of template system for generating your HTML files (like Jade, Dust, EJS, Handlebars, Nunjucks, PUG, etc..) and then you store some state in a database and use a query from the database as input to the template whenever you render a particular page.从概念上讲,您可能会使用某种模板系统来生成 HTML 文件(如 Jade、Dust、EJS、Handlebars、Nunjucks、PUG 等),然后将一些 state 存储在数据库中并使用数据库中的查询每当您呈现特定页面时作为模板的输入。

So, when you add an item to the database, it will show up in all future renders of the page.因此,当您将项目添加到数据库时,它将显示在页面的所有未来呈现中。

So, your button would trigger a form post to your server which would add an item to the database and the response from the form post would be a rendering of the page after adding the item to the database.因此,您的按钮将触发一个表单发布到您的服务器,这会将一个项目添加到数据库中,并且表单发布的响应将是在将项目添加到数据库后呈现页面。 All future renders of the page from all users would also show those same items in the rendered page.所有用户将来对页面的所有呈现也将在呈现的页面中显示这些相同的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Vuejs 和 Expressjs 中上传文件 - How do I upload FIle in Vuejs and Expressjs 在expressjs中使用响应对象提供HTML文件时,如何包含外部JavaScript文件? - How do I include an external JavaScript file when serving an HTML file with a response object in expressjs? 如何使用JavaScript写入html? - How do I write into the html using JavaScript? 如何使用来自expressjs的reactjs访问json? - How do I access json using reactjs from expressjs? 如何在 expressjs 中发送多部分响应? - How do I send a multipart response in expressjs? 如何使用 expressjs 发送多个文件? - How do I send multiple files with expressjs? 如何限制用户访问ExpressJS / NodeJS中的静态html文件? - How do I restrict the user from accessing the static html files in a ExpressJS/NodeJS? 使用HTML,如何将文件作为excel文件打开? - Using HTML, How do I open a file as an excel file? 我正在创建一个Mac应用程序,该应用程序需要读取和写入HTML文件。 我该如何实现? - I'm creating a Mac application that needs to read and write to/from an HTML file. How do I achieve this? 使用 ExpressJS,如何使用 URL 从 SQLite 表中提取不同的数据? - Using ExpressJS, how do I extract different data from a SQLite table using the URL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM