Reputation: 5854
index.js: (placed inside of server
folder.)
const serve = require('koa-static')
const Koa = require('koa');
const app = new Koa();
app.use(serve(__dirname + './public'));
app.listen(3000);
console.log('listening on port 3000');
I want to show index.html
, which is located in /public
folder.
When I start index.js
above, I see Not Found
on the browser.
console.log
shows, it's referring to same folder where index.js
is.
UPDATE 1:
console.log(__dirname + './public');
shows
/Users/askar/work/react/hub/server./public
,
but I need /Users/askar/work/react/hub/public
Upvotes: 4
Views: 5178
Reputation: 5854
Solution:
Changed from app.use(serve(__dirname + './public'));
To app.use(serve('./public'));
Reference: https://www.tutorialspoint.com/koajs/koajs_static_files.htm
Upvotes: 3