4

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

Askar
  • 5,784
  • 10
  • 53
  • 96

1 Answers1

3

Solution:

Changed from app.use(serve(__dirname + './public'));

To app.use(serve('./public'));

Reference: https://www.tutorialspoint.com/koajs/koajs_static_files.htm

Askar
  • 5,784
  • 10
  • 53
  • 96