This is what i have, the filename "default.htm" actually exists and loads when doing a readFile with NodeJS.
var express = require('express'); var app = express(); app.use(express.static(__dirname + '/default.htm')); app.listen(process.env.PORT);
The Error (in browser):
Cannot GET /
Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.
Problems occurring in Node. js application deployments can have a range of symptoms, but can generally be categorized into the following: Uncaught exception or error event in JavaScript code. Excessive memory usage, which may result in an out-of-memory error.
Express JS is minimal and unopinionated js” (ExpressJS, 2020). Express uses less overhead in the core framework so that makes it minimal and a good choice for building out large web applications. You don't want to have a framework that fills your codebase with lots of bloatware that you are never gonna use.
You cannot use Express without NodeJS by definition so you have to deploy your backend somewhere else in you want to use it.
You typically want to render templates like this:
app.get('/', function(req, res){ res.render('index.ejs'); });
However you can also deliver static content - to do so use:
app.use(express.static(__dirname + '/public'));
Now everything in the /public
directory of your project will be delivered as static content at the root of your site e.g. if you place default.htm
in the public folder if will be available by visiting /default.htm
Take a look through the express API and Connect Static middleware docs for more info.
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