An example of how to host an Express.js app on Netlify using serverless-http. See How to run Express.js apps with Netlify Functions for details.
index.pug simply loads html from the Express.js app using <object>
, and the
app is hosted at /.netlify/functions/server
.
Check out a working demo of this application at my custom Netlify link.
The most recent information from 2018 confirms that Netlify does not support sub-folders (though there is discussion about adding it to the UI). Therefore all of your project files must exist in the root. It should be noted that while your Netlify routes exist inserver.js
, your local routes exist as separate files in the routes
subdirectory. Any changes in these files during development must be manually changed in the server.js
file to take effect on Netlify.
To get started, ensure you have Node.js installed, then:
npm install
npm start
server-local.js
is our entry point. If you have nodemon, run:
nodemon server-local.js
Pug isn't supported on Netlify. Use pug-cli to compile pug into html.
npm install pug-cli
node node_modules/pug-cli/index.js pug/ --out ./views
Be sure the build command on Netlify includes the PUG conversion (set in the `netlify.toml file):
npm install && npm run build && node node_modules/pug-cli/index.js views/ --out ./
- Ethan Miller ethan.romans5.8@gmail.com
© 2019 Ethan Miller