Node.js quick file server (static files over HTTP)

前端 未结 30 2257
攒了一身酷
攒了一身酷 2020-11-22 12:30

Is there Node.js ready-to-use tool (installed with npm), that would help me expose folder content as file server over HTTP.

Example, if I have



        
30条回答
  •  眼角桃花
    2020-11-22 13:22

    connect could be what you're looking for.

    Installed easily with:

    npm install connect
    

    Then the most basic static file server could be written as:

    var connect = require('connect'),
        directory = '/path/to/Folder';
    
    connect()
        .use(connect.static(directory))
        .listen(80);
    
    console.log('Listening on port 80.');
    

提交回复
热议问题