Using node.js as a simple web server

后端 未结 30 2197
感情败类
感情败类 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条回答
  •  无人及你
    2020-11-22 03:15

    Basically copying the accepted answer, but avoiding creating a js file.

    $ node
    > var connect = require('connect'); connect().use(static('.')).listen(8000);
    

    Found it very convinient.

    Update

    As of latest version of Express, serve-static has become a separate middleware. Use this to serve:

    require('http').createServer(require('serve-static')('.')).listen(3000)
    

    Install serve-static first.

提交回复
热议问题