Build not failing yet page not found

Hello, I’m having problems deploying my node.js app with netlify
site url: msgbox.netlify.app
there seem to be no deployment errors, but visiting the site returns ‘page not found’. my index.js file is the following:

'use strict';
const express = require('express');
const app = express();
const path = require('path');
const serverless = require('serverless-http');
const bodyParser = require('body-parser');
const router = express.Router();

const views = path.join(__dirname, '../public')

router.get('/', (req, res) => {
  res.sendFile('index.html', { root: views });
});

app.use(bodyParser.json());
app.use('/.netlify/functions/server', router);

module.exports = app;
module.exports.handler = serverless(app);

Lots of the code above is copy-pasted, so let me know if I’m including something unnecessary
My repo is structured like this:

src
    index.js
public
    index.html

can someone please tell me why the build doesn’t fail yet my index.html file doesn’t show up?
thanks (:

@its-pablo It looks like you’re trying to run an express server to serve the html files yourself.

Netlify doesn’t operate like that, although you could do similar with Serverless Functions.

The default Netlify behavior is that the resulting files of your build are deployed to CDN.

So in your Build Settings if you set the Publish directory to public for example, it would upload and serve the index.html file that you have with no need for express.

1 Like