I am new to node.js and heroku. By following docs and some tutorials I have successfully deployed my app on heroku.
The problem I am facing is that I don't know how to run that deployed app on heroku. After reading a number of tutorials, its still not clear to me.
When I run the commands
$ git add .
$ git commit -am "make it better"
$ git push heroku master
from local command line, it executes the scripts. But when I click on the open app from the heroku account, it does not execute all of files.
I am running 1 web dynos and heroku shows that my web dyno executes following command
web node build/server.js
The server.js
file contains following code
require('./routes/main.routes.js');
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("this is a test page");
}).listen(process.env.PORT);
when I click on open app from heroku, it opens the app in the browser with message
this is a test page
It does not run the main.routes.js
file.
But when I click on restart all Dynos, the main.routes.js
file also gets executed. I want the app to execute the main.routes.js
file when I click on open my app or refresh it in the browser window.
Is the restart all Dynos only way to execute script? or I have done something wrong?
Any help will be much appreciated.
You can try this replace the comment (//write the code here) and try requesting the url:
var http = require('http');
http.createServer(function (req, res) {
// write the code here if it needs to execute every time
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("this is a test page");
}).listen(process.env.PORT);