nodejs send html file to client

后端 未结 3 1093
迷失自我
迷失自我 2021-01-30 17:10

I use this function to send html file to client, but in client I get nothing (blank page) without error. Something I wrong?, please help?

var express = require(\         


        
3条回答
  •  无人及你
    2021-01-30 17:56

    Try your code like this:

    var app = express();
    app.get('/test', function(req, res) {
        res.sendFile('views/test.html', {root: __dirname })
    });
    
    1. Use res.sendFile instead of reading the file manually so express can handle setting the content-type properly for you.

    2. You don't need the app.engine line, as that is handled internally by express.

提交回复
热议问题