I've created a project consisting only HTML files and I want to deploy this on Heroku. So I've created a dummy backend to deploy on Heroku but when I run this on localhost then it shows me an error that no such file or directory
error pic:
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname 'project.html'));
});
// add other routes below
app.get('/Vaccine2', function(req, res) {
res.sendFile(path.join(__dirname 'Vaccine2.html'));
});
app.get('/hospital', function(req, res) {
res.sendFile(path.join(__dirname 'hospital.html'));
});
app.listen(process.env.PORT || 3000);
CodePudding user response:
Add a backslash \ to the file names.
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname '\project.html'));
});
// add other routes below
app.get('/Vaccine2', function(req, res) {
res.sendFile(path.join(__dirname '\Vaccine2.html'));
});
app.get('/hospital', function(req, res) {
res.sendFile(path.join(__dirname '\hospital.html'));
});
CodePudding user response:
First delete a branch in Git
rm -rf .git
after then create an src directory on the project
and change your code
this:
app.use('/src', express.static(path.join(__dirname)));
to this:
app.use('/src', express.static(path.join(__dirname '/src')));
go your package.json file and add your node.js version like:
"engines": {
"node": "14.x"
}
and try deploy your website again
git add .
git commit -m "Added a Procfile."
heroku login
Enter your Heroku credentials.
...
heroku create
Creating arcane-lowlands-8408... done, stack is cedar
http://arcane-lowlands-8408.herokuapp.com/ | [email protected]:arcane-
lowlands-8408.git
Git remote heroku added
git push heroku main
...
-----> Node.js app detected
...
-----> Launching... done
http://arcane-lowlands-8408.herokuapp.com deployed to Heroku
Some Recorses you can check it out:
First think first be sure the you type all comments correctly in heroku. Feel free to send a message back if you will figure it out or not.

