Basic webserver with node.js and express for serving html file and assets

后端 未结 4 1912
失恋的感觉
失恋的感觉 2021-01-30 06:37

I\'m making some frontend experiments and I\'d like to have a very basic webserver to quickly start a project and serve the files (one index.html file + some css/js/img files).

4条回答
  •  一整个雨季
    2021-01-30 07:27

    I came across this because I have a similar situation. I don't need or like templates. Anything you put in the public/ directory under express gets served as static content (Just like Apache). So I placed my index.html there and used sendfile to handle requests with no file (eg: GET http://mysite/):

    app.get('/', function(req,res) {
      res.sendfile('public/index.html');
    });
    

提交回复
热议问题