Using node.js as a simple web server

后端 未结 30 2240
感情败类
感情败类 2020-11-22 02:54

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same

30条回答
  •  旧时难觅i
    2020-11-22 03:16

    This is basically an updated version of the accepted answer for connect version 3:

    var connect = require('connect');
    var serveStatic = require('serve-static');
    
    var app = connect();
    
    app.use(serveStatic(__dirname, {'index': ['index.html']}));
    app.listen(3000);
    

    I also added a default option so that index.html is served as a default.

提交回复
热议问题