如何快速启动静态文件服务器

February 1, 2024

Python 的 http.server

$ python3 -m http.server
# Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...


$ python3 -m http.server -d ~/Pictures/
# Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

npm 上的 http-server

按需运行:

用 npx 可以直接运行,无需事先手动安装:

npx http-server [path] [options]

npm 上的 serve

也可以全局安装这个包(需要 Node.js LTS 或更高版本):

npm install --global serve

serve folder-name/

# 用下面的命令查看所有可用选项:
serve --help

© 2024 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2024-02-01). 如何快速启动静态文件服务器. https://caiborui.com/blog/2024-02-01-en-quick-staticserver-zhtrans

@misc{borui2024-f1809b36,
  author = {borui},
  title = {{如何快速启动静态文件服务器}},
  year = {2024},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2024-02-01-en-quick-staticserver-zhtrans}
}