Include HTML blocks Using node.js

前端 未结 5 633
生来不讨喜
生来不讨喜 2021-02-04 09:01

This is what I want but probably can\'t have:

Using node.js and express and maybe ejs, I would like to, while writing a regular HTML file in my client dir, server-side-i

5条回答
  •  庸人自扰
    2021-02-04 09:11

    var express = require('express');
    var app = express();
    var path = require('path');
    
    app.get("/" ,(req,res) => {
         res.sendFile(path.join(__dirname+'../../templates/index.html')); 
    });
    app.use(express.static(path.join(__dirname+'../../templates/public')));
    

    This way you can call HTML where ever the folder that contains HTML. if you want to include CSS and Javascript use express.static see the last line of code

提交回复
热议问题