simplest way to have Express serve a default page?

后端 未结 4 567
误落风尘
误落风尘 2021-01-01 12:16

I\'m using this to have Node.js/Express setup as a rudimentary web server - it just serves a set of static pages without any other processing. I\'d like it to always serve /

4条回答
  •  梦谈多话
    2021-01-01 13:05

    You could do something like this. Assuming its an html file that is relative to the .js file:

    app.get('/', function(req, res){
        res.sendfile('default.html', { root: __dirname + "/relative_path_of_file" } );
    });
    

提交回复
热议问题