如何修改http-server默认路径:存在public时指定根目录启动
public Folder Exists No sweat, here's a simple, direct fix for your use case:
- Explicitly set your project root as the server's target path using the
[path]parameter. This will override http-server's default behavior of prioritizing thepublicfolder if it exists.
Just run this command in your project's root directory:
http-server ./
This forces http-server to serve files directly from your root folder, so it will load the index.html located there instead of looking inside the public directory.
Quick Extra Tip
If you ever need to serve files from a different custom directory down the line, you can use the same pattern—just replace ./ with the path to your target folder. For example:
http-server ./my-test-build
The core logic here is that the explicit [path] argument always takes priority over http-server's automatic folder detection. This lets you fully control which directory gets served, regardless of whether a public folder exists.
内容的提问来源于stack exchange,提问作者Satyajit Das

