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

前端 未结 30 2198
攒了一身酷
攒了一身酷 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:02

    Here is my one-file/lightweight node.js static file web-server pet project with no-dependency that I believe is a quick and rich tool which its use is as easy as issuing this command on your Linux/Unix/macOS terminal (or termux on Android) when node.js (or nodejs-legacy on Debian/Ubuntu) is installed:

    curl pad.js.org | node 
    

    (different commands exist for Windows users on the documentation)

    It supports different things that I believe can be found useful,

    • Hierarchical directory index creation/serving
      • With sort capability on the different criteria
      • Upload from browser by [multi-file] drag-and-drop and file/text-only copy-paste and system clipboard screen-shot paste on Chrome, Firefox and other browsers may with some limitations (which can be turned off by command line options it provides)
      • Folder/note-creation/upload button
    • Serving correct MIMEs for well known file types (with possibility for disabling that)
    • Possibility of installation as a npm package and local tool or, one-linear installation as a permanent service with Docker
    • HTTP 206 file serving (multipart file transfer) for faster transfers
    • Uploads from terminal and browser console (in fact it was originally intended to be a file-system proxy for JS console of browsers on other pages/domains)
    • CORS download/uploads (which also can be turned off)
    • Easy HTTPS integration
    • Lightweight command line options for achieving better secure serving with it:
      • With my patch on node.js 8, you can have access to the options without first installation: curl pad.js.org | node - -h
      • Or first install it as a system-global npm package by [sudo] npm install -g pad.js and then use its installed version to have access to its options: pad -h
      • Or use the provided Docker image which uses relatively secure options by default. [sudo] docker run --restart=always -v /files:/files --name pad.js -d -p 9090:9090 quay.io/ebraminio/pad.js

    Screenshot of a folder index using the tool

    The features described above are mostly documented on the main page of the tool http://pad.js.org which by some nice trick I used is also the place the tool source itself is also served from!

    The tool source is on GitHub which welcomes your feedback, feature requests and ⭐s!

提交回复
热议问题