Basic static file server in NodeJS

后端 未结 8 781
盖世英雄少女心
盖世英雄少女心 2020-11-28 20:06

I\'m trying to create a static file server in nodejs more as an exercise to understand node than as a perfect server. I\'m well aware of projects like Connect and node-stati

8条回答
  •  囚心锁ツ
    2020-11-28 20:20

    the st module makes serving static files easy. Here is an extract of README.md:

    var mount = st({ path: __dirname + '/static', url: '/static' })
    http.createServer(function(req, res) {
      var stHandled = mount(req, res);
      if (stHandled)
        return
      else
        res.end('this is not a static file')
    }).listen(1338)
    

提交回复
热议问题