简体   繁体   English

如何将引导程序 css 样式表合并到我的 express/node js 中?

[英]How would I incorporate a bootstrap css stylesheet into my express/node js?

So at the moment, the approach I am taking is I'm using this code to retrieve my html file.所以目前,我采用的方法是使用此代码检索我的 html 文件。

app.get("/", function (request, response) {
response.sendFile(__dirname + "/public_html/index.html");
})

The html file is a form with method="post" and a button to submit the form. html 文件是一个带有 method="post" 的表单和一个提交表单的按钮。 I have imported the relevant css code here.我已经在这里导入了相关的 css 代码。

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
    integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

Back on the js side I have use this code to collect the values from the html form when it is submitted.回到 js 端,我在提交时使用此代码从 html 表单中收集值。

app.post("/survey", function (request, response, next) {
let firstname = request.body.fname;
let surname = request.body.sname;
etc...

Then here is the part where I'm not sure whether or not I'm taking the wrong approach or not.然后这是我不确定我是否采取错误方法的部分。

I use some response.write() methods to display the form results.我使用一些 response.write() 方法来显示表单结果。

response.write('<h1>SURVEY REPORT</h1>');
response.write('<dl><dd><strong>Firstname entered: </strong>' + firstname + '</dd>');
response.write('<dd><strong>Surname entered: </strong>' + surname + '</dd>');
etc...

While this does kind of work, it doesn't seem to implement the css stylesheet at all.虽然这确实有效,但它似乎根本没有实现 css 样式表。 How would I get the css stylesheet to work with the output?如何让 css 样式表与 output 一起使用?

I have also tried creating a sql database in memory via sqlite3 and store the values there, but now I'm stuck with how I would use that table to output into an html format. I have also tried creating a sql database in memory via sqlite3 and store the values there, but now I'm stuck with how I would use that table to output into an html format.

It is not a better way to do You can you Handlebars or ejs.这不是更好的方法你可以使用Handlebars或 ejs。

Add this line on app.js在 app.js 上添加这一行

app.set('view engine', 'hbs');

Then you can response to the request by:-然后您可以通过以下方式响应请求:-

res.render('/filepath/index.hbs', {write variables for the file as json})

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

相关问题 如何在Express&Node.js中创建一个包含所有.html模板的.js文件? - How would I create a .js file that contains all of my .html templates in Express & Node.js? 如何使用 express 读取我的 css 文件 node.js - How to read my css file with express, node.js 如何将我的node.js文件合并到邮递员请求中? - how do I incorporate my node.js file into a postman request? 如何在我的Node.js应用程序中整合模型和控制器? - How Do I Incorporate Models and Controllers In My Node.js App? 静态文件,带有Node.js和Express的样式表 - Static file, stylesheet with Node.js and Express 如何修复 Express + ESJ 项目中的 CSS 样式表路径 - How can I fix CSS stylesheet path in Express + ESJ project Node.js无法识别Express对象,并且无法设置CSS / JS的路径 - Node.js won't recognise an Express object & I can't set paths to my CSS/JS 如何将JS库合并到我的NPM构建脚本中? - How can I incorporate JS libraries into my NPM build script? 浏览器不会使用 express 和 node 为我的本地网站加载 css 样式表 - browser won't load css stylesheet for my local website using express and node 如果我使用 jQuery 的 ajax 方法将 CSV 文件发送到服务器,文件将位于我的 Node.js + Express 服务器上的什么位置? - Where would a file be located on my Node.js + Express server if I send a CSV file to the server using jQuery's ajax method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM