常问问题
应该如何构建我的应用程序?
这个问题没有确定的答案。答案取决于您的应用程序的规模和所涉及的团队。为了尽可能灵活,Express 在结构方面不做任何假设。
路由和其他特定于应用程序的逻辑可以存在于您喜欢的任何目录结构中的任意数量的文件中。查看以下示例以获得灵感:
此外,Express 还有第三方扩展,可以简化其中一些模式:
如何定义模型?
lSvmQOi4wAdm49sUBfuR/zY+J5aKLZnqhT30Go4KYIIhMq4eBb9xDIvbDOtHditnFzjmYYz9HZi/OMjspos2dbtQ8hTqBNJp7+lXVX6g4ipcU5uQlLXZCARuk5hQfCvkbDKFn8eMRoNMIJfBq3IOpd57kQjFfLLHizFBf3J4l2Q=
znSTwv/rnwU22GMDjScF4pxTU7GMqDl8c9EDZtMCARn4vrf9WDZLk2lmSqwxEMT/OBQIxjyaquup9wN3AcqZ8r0jBJJ89G8AEkPuAwC02cbHMB+0AvwkoqzoHJJOY0c+NK/k/e/bgXs7VJXQdzXNNxW1DBcFiEsQ37uZnytu1jk=
如何验证用户身份?
WXnoYqeJaW2qJZgDhBxAJmbodsuckVljevo2kZ/LqNl2mL0cGIZQnFK5h7MAwJJPzl3Lre+tgEFPItlrciicpSSj0+bYJWPCJ92k0skJWgCOFNaH8kcaKSqEoq29QsK7nAEW0jp7byoKzn4CkGEtsp6CZc6ccOUGm7FFYXwSmDgWTNxR2Cl05TiOng4LpobmRFnQDRWgzxLdfJSvjvNJ3eF4lvHPfeNVFVpK1kmDrcFq3pEd7dvN1KWOWZlROQggXhu1w5BhieWkAlhpS4Mr9x0ORvGcMVRajRtTvH20b5g42l5zHdZM8KILcYq6YgIEs4GcUNYzUjJRw28N+B0RzQ==
Express 支持哪些模板引擎?
9PHcim3gtD617tOQwiyC/njdQvhcUu/BW1Lw+yYNSPZ38m0jAM0oGpK8pJQhroXXF/0MxHnFffSYBdWGzbE5TCHbtCEarqqFKq7ZKfV6uxFkZFT0yk4StYrOTN6YKsM8IId54JVUEktFH9Zo6FQK0xLESxaaGmk9Hgxl/wQX6cRNLwr9rHCz0Kf+WMgJQeAWqsmV6KcUUbUEy1TBfLTeqVeAFZwyRBMFsJUEV1dhiHUXWuitr5fhBi5Eeg6hNSHxGkfB5LQUK+lQprofbKpug5dmEt1BXOVH0fHi+vIsBuRuuyt47933uHtRMZtAMNrvbfNKNMp0ZfxdQ9tSF/SopReHFxxMaK2oTyKvXcvOkoZsHQnJ2FNv8/RCRyazWtek
VivJNzmMQpLrRMAUeex2hx2LgN3m00O/QpoDVfIVW1JBfgPJCGCFDZb119V2oyTvt4l5aH4wW2sQBxRziuZmgTi/JG5Qt6bClyRD+eJeIoBUSE5QglZ0DDsE5zck/uE8j7LTUOr1TNBWNo8qgT0sFA==
如何处理 404 响应?
9SpAP1ShrxHn7YtG7U/w3yukd11eibDpzydFm33RBt1kAlEjROrAR/TmoI3/KOW0bLRH/81nSylwkIg4l6YPS1IQQin6T5YHTMQ7iW+m5LPx3wJqP75IDPV7rAa44DCfqz62TyyvOn+7XmrlUU6WZyGKqqhRIlmvW23BJKl5tatSUjx79mrXzRarrnrrdrsdUH1NomvQr1LWNiJqooyjF5rkr/Sldbzmczw+1EeX0vrK3SPRyd6GZxaas2cMV7R0ZVkJ/cb3/nim0esReoVDWFU3Hh9Mdv1Y6h3PQUI0hYo92NhgKUsLqomRc0fMVB3TGb1HTy8pr1O399mK5/FIpL9ZLoLxe8UMeSoOarnxS6wx679ziWe6YSdo53O9a5DhH2xIsIno3UTt0K8hw4V/tndJrqXS6WGRZ/sRF3ljPUcSVjFgUaTV4/IEAqwgD74Ud3WUUHS0fEQrJ0yKV0yT0IFgegNu8ivfNSNe5u+dOX0osKeJ1+CD+pEfGDqIzyvIC11HWejyxUfecikWbMHUdrrBHlPm0D9uV9goTEgRLd4=
app.use((req, res, next) => {
res.status(404).send("Sorry can't find that!")
})
YoGK2LfIJZ8GZZiRpGSLhniEkNeqsM4ceU8s+F4GsnY0PqKNF//lXljW6vbR0ML4g+FAwcIi+PtUJAS/eOqKHw/19xsOfd3Xh4Bg215Zm7NHOutfr89GAfyux0dpUiRYJ4HyVtyP/pJHScOi5TsM2MGJUHaJspvxQLtr0+CT/uA=
如何设置错误处理程序?
y9yxLhIBFN073qKM11mEJfx3cOtjKfe6LNnT6qnHcVJRUOaUPRE2B3dfsvMhEZu6h8a2StOlrVYrNP2oyI9wmLKxP/k2ab7ohOLulJuGXjr15tHfWh8iucSqy1h61VmOvsVLigoPWyAXUK68c7jYmhUapRSjxbF95cV2G9r4IhOiGmiYfsHDpLylvvUeHvRmchI69LBir4tvIdLUl2RNRte7xyk/wOETaFHiDSITiSU=
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send('Something broke!')
})
VivJNzmMQpLrRMAUeex2hx2LgN3m00O/QpoDVfIVW1IJZ8CF5joq0/pd5kOlROtwRYZ7qbYZomGsIsAvF2Sif6LX/EZvOQessk73LdnRrEKDc46r0+QQM0QVZZvqVbeL
如何呈现纯 HTML?
htGsszkMqiIH1ZBXNUhX2ka0WoL9oreuJGLZ0O4Kjf+xDih2ePEPjBapfjlcBlp8uiGYlmkz5ZN3zzKKF6TVDXlBifcmdcaT0D+qgj48keH4gcV3Rz6TRiXU0kRODTIWza8L/VUzb0OQ1uaY3n/quP8mtDqG97YBrlS0q7H9pVZjyt4c0UsNuTf57gNt63cXdLPcYbBTR5bFZiEBvfgVq9sAmoDX8B17q6TvcANhRjooUK1FQ4wwTlwoy/hqyj2sGe2K2pVzoS5ltHyaO3rS8P/HBwfDOOeFblnML4MtzwerAxVxlkgvXVoTKI99V0QCPxL4GmgADPTISMxHi355+lSfnV3Zxwn71B6tFd/HIHY=