ZeroCho / nodejs-book

Node.js교과서 소스 코드
808 stars 645 forks source link

[p.256] express.static 미들웨어 첫 번째 인수로 인한 에러 #759

Open wiseguy77 opened 1 year ago

wiseguy77 commented 1 year ago

[도서 내 소스] app.use( morgan('dev'), express.static( '/', path.join(__dirname, 'public')), ... );

[에러로그] /Users/wise/study/nodejs/nodejs-textbook/learn-express/node_modules/serve-static/index.js:48 var opts = Object.create(options || null) ^ TypeError: Object prototype may only be an Object or null: /Users/wise/study/nodejs/nodejs-textbook/learn-express/public at Function.create () at Function.serveStatic [as static] (/Users/wise/study/nodejs/nodejs-textbook/learn-express/node_modules/serve-static/index.js:48:21) at Object. (/Users/wise/study/nodejs/nodejs-textbook/learn-express/app.js:21:32) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47

[해결] p.249 예제처럼 express.static( path.join(__dirname, 'public'))로 수정하면 정상 작동하네요.

ZeroCho commented 1 year ago

app.use('/', morgan('dev'), express.static(path.join(__dirname, 'public')), ... ); 인데 실수했네요. 감사합니다