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
Solution:
Changed from app.use(serve(__dirname + './public'));
To app.use(serve('./public'));
Reference: https://www.tutorialspoint.com/koajs/koajs_static_files.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With