Express Static nodejs

后端 未结 3 1402
[愿得一人]
[愿得一人] 2020-12-07 03:53

There is a style.css in public, but I can\'t seem to make the express static option work. I deleted express and have done npm i

3条回答
  •  天命终不由人
    2020-12-07 04:29

    Works just fine for me.

    app.js

    var express = require('express')
      , app = express.createServer();
    
    app.use(express.static(__dirname+'/public'));
    
    app.listen(8080, "127.0.0.1");
    

    mkdir public
    cd public
    touch README
    

    README

    test
    

    $ curl http://localhost:8080/README
    test
    

    $ npm ls
    connect@1.6.1
    express@2.4.4
    

提交回复
热议问题