Files
2018-10-16 21:32:40 +05:30

19 lines
889 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Serve an HTML File
localeTitle: 提供HTML文件
---
## 提供HTML文件
你可能需要评论最后的挑战。如果您有一个网站并想要提供index.html文件您可能希望将其放在公共文件夹中。这是为了确保公众看不到你不想要的东西它有时被称为“公共”或“观点”但你可以从技术上称之为你想要的任何东西。
要在根域中名为“public”的文件夹中提供index.html您可以这样做
```javascript
app.get("/", function(req, res) {
res.sendFile( __dirname + "/public/index.html");
});
```
注意:\_\_dirname返回根目录是节点开发人员的最佳实践。
[帮助我们的社区扩展这些提示和指南](https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/apis-and-microservices/basic-node-and-express/serve-an-html-file/index.md) 。