Error: ENOENT: no such file or directory, stat '/public/main.html' at Error (native)

Since both the server and the index file are INSIDE the "public" directory, you can simply use :

res.sendfile('./main.html');

To answer the question in the comments : In Express 4.x, the sendfile method was replaced by the sendFile method (all lowercase -> camelCase). Probably just an oversight in early versions, that got fixed in the latter.


I had a similar issue when I referred to dist folder. the relative path to index.html was:

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'dist/project-name/index.html'));
});

You missed the dot. Keep in mind relative directory is

res.sendfile('./public/main.html');