![](/img/trans.png)
[英]Basic webserver with node.js and express for serving html file and assets
[英]Basic Node and Express: Serve Static Assets with file directory
let express = require('express');
let app = express();
app.use(express.static('public'));
我正在嘗試解決 freecodecamp 的“基本節點和 Express:服務 Static 資產”挑戰,但它一直說“不工作。有人可以幫助我嗎?謝謝。
作為參考,這里提到了解決方案: https://forum.freecodecamp.org/t/basic-node-and-express-serve-static-assets/556796但它不起作用。 無論如何,我會遷移到 codeacademy。
這是路徑文件夾我的目錄中的主要文件
利用:
app.use(express.static('./public'));
如快速文檔中所述:
如果您從另一個目錄運行 express 應用程序,使用您要服務的目錄的絕對路徑會更安全:
const path = require('path')
app.use('/static', express.static(path.join(__dirname, 'public')))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.