Heroku NodeJS - Cannot GET /
I have a Heroku server with BootBot running over it. But I'm having difficulties trying to render a HTML page from it. This is what I'm doing:
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/test', function (req, res) {
res.sendFile(path.join(__dirname + 'test.html'));
});
app.listen(3000, function() {
console.log("The server is running.");
});
My root directory has both index.js and test.html.
My Procfile is:
web: node --inspect ./index.js
Everything I've tried sends me to the same "Cannot GET /test".
Is there something I'm missing?
If I set app.listen(process.env.PORT)
State changed from starting to crashed
2018-11-22T09:48:29.702624+00:00 heroku[web.1]: Process exited with status 1
2018-11-22T09:48:29.606583+00:00 app[web.1]: The server is running.
2018-11-22T09:48:29.608553+00:00 app[web.1]: events.js:167
2018-11-22T09:48:29.608557+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-11-22T09:48:29.608558+00:00 app[web.1]: ^
2018-11-22T09:48:29.608559+00:00 app[web.1]:
2018-11-22T09:48:29.608561+00:00 app[web.1]: Error: listen EADDRINUSE :::20293
2018-11-22T09:48:29.608563+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1286:14)
2018-11-22T09:48:29.608564+00:00 app[web.1]: at listenInCluster (net.js:1334:12)
2018-11-22T09:48:29.608565+00:00 app[web.1]: at Server.listen (net.js:1421:7)
2018-11-22T09:48:29.608569+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-11-22T09:48:29.608570+00:00 app[web.1]: at BootBot.start (/app/node_modules/bootbot/lib/BootBot.js:46:28)
2018-11-22T09:48:29.608572+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:550:5)
2018-11-22T09:48:29.608573+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-11-22T09:48:29.608574+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-11-22T09:48:29.608576+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-11-22T09:48:29.608577+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-11-22T09:48:29.608579+00:00 app[web.1]: Emitted 'error' event at:
2018-11-22T09:48:29.608580+00:00 app[web.1]: at emitErrorNT (net.js:1313:8)
2018-11-22T09:48:29.608581+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2018-11-22T09:48:29.608583+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
2018-11-22T09:48:29.608584+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2018-11-22T09:48:29.608585+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
javascript html node.js express
|
show 1 more comment
I have a Heroku server with BootBot running over it. But I'm having difficulties trying to render a HTML page from it. This is what I'm doing:
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/test', function (req, res) {
res.sendFile(path.join(__dirname + 'test.html'));
});
app.listen(3000, function() {
console.log("The server is running.");
});
My root directory has both index.js and test.html.
My Procfile is:
web: node --inspect ./index.js
Everything I've tried sends me to the same "Cannot GET /test".
Is there something I'm missing?
If I set app.listen(process.env.PORT)
State changed from starting to crashed
2018-11-22T09:48:29.702624+00:00 heroku[web.1]: Process exited with status 1
2018-11-22T09:48:29.606583+00:00 app[web.1]: The server is running.
2018-11-22T09:48:29.608553+00:00 app[web.1]: events.js:167
2018-11-22T09:48:29.608557+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-11-22T09:48:29.608558+00:00 app[web.1]: ^
2018-11-22T09:48:29.608559+00:00 app[web.1]:
2018-11-22T09:48:29.608561+00:00 app[web.1]: Error: listen EADDRINUSE :::20293
2018-11-22T09:48:29.608563+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1286:14)
2018-11-22T09:48:29.608564+00:00 app[web.1]: at listenInCluster (net.js:1334:12)
2018-11-22T09:48:29.608565+00:00 app[web.1]: at Server.listen (net.js:1421:7)
2018-11-22T09:48:29.608569+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-11-22T09:48:29.608570+00:00 app[web.1]: at BootBot.start (/app/node_modules/bootbot/lib/BootBot.js:46:28)
2018-11-22T09:48:29.608572+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:550:5)
2018-11-22T09:48:29.608573+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-11-22T09:48:29.608574+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-11-22T09:48:29.608576+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-11-22T09:48:29.608577+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-11-22T09:48:29.608579+00:00 app[web.1]: Emitted 'error' event at:
2018-11-22T09:48:29.608580+00:00 app[web.1]: at emitErrorNT (net.js:1313:8)
2018-11-22T09:48:29.608581+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2018-11-22T09:48:29.608583+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
2018-11-22T09:48:29.608584+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2018-11-22T09:48:29.608585+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
javascript html node.js express
1
use.listen(process.env.PORT || 3000)instead. stackoverflow.com/questions/15693192/…
– William Chong
Nov 22 '18 at 9:17
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
That's why he placed a||if process.env isn't defined, it takes the3000
– Izio
Nov 22 '18 at 9:26
Heroku defines what port it wants to use with environment variablePORT, it might not be 3000 in most cases
– William Chong
Nov 22 '18 at 9:28
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50
|
show 1 more comment
I have a Heroku server with BootBot running over it. But I'm having difficulties trying to render a HTML page from it. This is what I'm doing:
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/test', function (req, res) {
res.sendFile(path.join(__dirname + 'test.html'));
});
app.listen(3000, function() {
console.log("The server is running.");
});
My root directory has both index.js and test.html.
My Procfile is:
web: node --inspect ./index.js
Everything I've tried sends me to the same "Cannot GET /test".
Is there something I'm missing?
If I set app.listen(process.env.PORT)
State changed from starting to crashed
2018-11-22T09:48:29.702624+00:00 heroku[web.1]: Process exited with status 1
2018-11-22T09:48:29.606583+00:00 app[web.1]: The server is running.
2018-11-22T09:48:29.608553+00:00 app[web.1]: events.js:167
2018-11-22T09:48:29.608557+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-11-22T09:48:29.608558+00:00 app[web.1]: ^
2018-11-22T09:48:29.608559+00:00 app[web.1]:
2018-11-22T09:48:29.608561+00:00 app[web.1]: Error: listen EADDRINUSE :::20293
2018-11-22T09:48:29.608563+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1286:14)
2018-11-22T09:48:29.608564+00:00 app[web.1]: at listenInCluster (net.js:1334:12)
2018-11-22T09:48:29.608565+00:00 app[web.1]: at Server.listen (net.js:1421:7)
2018-11-22T09:48:29.608569+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-11-22T09:48:29.608570+00:00 app[web.1]: at BootBot.start (/app/node_modules/bootbot/lib/BootBot.js:46:28)
2018-11-22T09:48:29.608572+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:550:5)
2018-11-22T09:48:29.608573+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-11-22T09:48:29.608574+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-11-22T09:48:29.608576+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-11-22T09:48:29.608577+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-11-22T09:48:29.608579+00:00 app[web.1]: Emitted 'error' event at:
2018-11-22T09:48:29.608580+00:00 app[web.1]: at emitErrorNT (net.js:1313:8)
2018-11-22T09:48:29.608581+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2018-11-22T09:48:29.608583+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
2018-11-22T09:48:29.608584+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2018-11-22T09:48:29.608585+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
javascript html node.js express
I have a Heroku server with BootBot running over it. But I'm having difficulties trying to render a HTML page from it. This is what I'm doing:
var app = express();
var path = require('path');
app.use(express.static(path.join(__dirname)));
app.get('/test', function (req, res) {
res.sendFile(path.join(__dirname + 'test.html'));
});
app.listen(3000, function() {
console.log("The server is running.");
});
My root directory has both index.js and test.html.
My Procfile is:
web: node --inspect ./index.js
Everything I've tried sends me to the same "Cannot GET /test".
Is there something I'm missing?
If I set app.listen(process.env.PORT)
State changed from starting to crashed
2018-11-22T09:48:29.702624+00:00 heroku[web.1]: Process exited with status 1
2018-11-22T09:48:29.606583+00:00 app[web.1]: The server is running.
2018-11-22T09:48:29.608553+00:00 app[web.1]: events.js:167
2018-11-22T09:48:29.608557+00:00 app[web.1]: throw er; // Unhandled 'error' event
2018-11-22T09:48:29.608558+00:00 app[web.1]: ^
2018-11-22T09:48:29.608559+00:00 app[web.1]:
2018-11-22T09:48:29.608561+00:00 app[web.1]: Error: listen EADDRINUSE :::20293
2018-11-22T09:48:29.608563+00:00 app[web.1]: at Server.setupListenHandle [as _listen2] (net.js:1286:14)
2018-11-22T09:48:29.608564+00:00 app[web.1]: at listenInCluster (net.js:1334:12)
2018-11-22T09:48:29.608565+00:00 app[web.1]: at Server.listen (net.js:1421:7)
2018-11-22T09:48:29.608569+00:00 app[web.1]: at Function.listen (/app/node_modules/express/lib/application.js:618:24)
2018-11-22T09:48:29.608570+00:00 app[web.1]: at BootBot.start (/app/node_modules/bootbot/lib/BootBot.js:46:28)
2018-11-22T09:48:29.608572+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:550:5)
2018-11-22T09:48:29.608573+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-11-22T09:48:29.608574+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-11-22T09:48:29.608576+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:598:32)
2018-11-22T09:48:29.608577+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
2018-11-22T09:48:29.608579+00:00 app[web.1]: Emitted 'error' event at:
2018-11-22T09:48:29.608580+00:00 app[web.1]: at emitErrorNT (net.js:1313:8)
2018-11-22T09:48:29.608581+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2018-11-22T09:48:29.608583+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
2018-11-22T09:48:29.608584+00:00 app[web.1]: at startup (internal/bootstrap/node.js:285:19)
2018-11-22T09:48:29.608585+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
javascript html node.js express
javascript html node.js express
edited Nov 22 '18 at 9:50
Macaret
asked Nov 22 '18 at 9:05
MacaretMacaret
296422
296422
1
use.listen(process.env.PORT || 3000)instead. stackoverflow.com/questions/15693192/…
– William Chong
Nov 22 '18 at 9:17
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
That's why he placed a||if process.env isn't defined, it takes the3000
– Izio
Nov 22 '18 at 9:26
Heroku defines what port it wants to use with environment variablePORT, it might not be 3000 in most cases
– William Chong
Nov 22 '18 at 9:28
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50
|
show 1 more comment
1
use.listen(process.env.PORT || 3000)instead. stackoverflow.com/questions/15693192/…
– William Chong
Nov 22 '18 at 9:17
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
That's why he placed a||if process.env isn't defined, it takes the3000
– Izio
Nov 22 '18 at 9:26
Heroku defines what port it wants to use with environment variablePORT, it might not be 3000 in most cases
– William Chong
Nov 22 '18 at 9:28
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50
1
1
use
.listen(process.env.PORT || 3000) instead. stackoverflow.com/questions/15693192/…– William Chong
Nov 22 '18 at 9:17
use
.listen(process.env.PORT || 3000) instead. stackoverflow.com/questions/15693192/…– William Chong
Nov 22 '18 at 9:17
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
That's why he placed a
|| if process.env isn't defined, it takes the 3000– Izio
Nov 22 '18 at 9:26
That's why he placed a
|| if process.env isn't defined, it takes the 3000– Izio
Nov 22 '18 at 9:26
Heroku defines what port it wants to use with environment variable
PORT, it might not be 3000 in most cases– William Chong
Nov 22 '18 at 9:28
Heroku defines what port it wants to use with environment variable
PORT, it might not be 3000 in most cases– William Chong
Nov 22 '18 at 9:28
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50
|
show 1 more comment
1 Answer
1
active
oldest
votes
You need template engine like ejs or blade when you want to render html page from node.Js.
npm install ejs --save
And these lines to your index.js file
// ~ render html files with ejs
app.use(express.static(path.join(__dirname)));
app.set('views', __dirname);
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.get('/test', function (req, res, next) {
res.render('test.html');
});
I hope this helps you. if it does not reach me with the comments.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427256%2fheroku-nodejs-cannot-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need template engine like ejs or blade when you want to render html page from node.Js.
npm install ejs --save
And these lines to your index.js file
// ~ render html files with ejs
app.use(express.static(path.join(__dirname)));
app.set('views', __dirname);
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.get('/test', function (req, res, next) {
res.render('test.html');
});
I hope this helps you. if it does not reach me with the comments.
add a comment |
You need template engine like ejs or blade when you want to render html page from node.Js.
npm install ejs --save
And these lines to your index.js file
// ~ render html files with ejs
app.use(express.static(path.join(__dirname)));
app.set('views', __dirname);
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.get('/test', function (req, res, next) {
res.render('test.html');
});
I hope this helps you. if it does not reach me with the comments.
add a comment |
You need template engine like ejs or blade when you want to render html page from node.Js.
npm install ejs --save
And these lines to your index.js file
// ~ render html files with ejs
app.use(express.static(path.join(__dirname)));
app.set('views', __dirname);
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.get('/test', function (req, res, next) {
res.render('test.html');
});
I hope this helps you. if it does not reach me with the comments.
You need template engine like ejs or blade when you want to render html page from node.Js.
npm install ejs --save
And these lines to your index.js file
// ~ render html files with ejs
app.use(express.static(path.join(__dirname)));
app.set('views', __dirname);
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.get('/test', function (req, res, next) {
res.render('test.html');
});
I hope this helps you. if it does not reach me with the comments.
answered Nov 22 '18 at 10:50
bereket gebredinglebereket gebredingle
1,056618
1,056618
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427256%2fheroku-nodejs-cannot-get%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
use
.listen(process.env.PORT || 3000)instead. stackoverflow.com/questions/15693192/…– William Chong
Nov 22 '18 at 9:17
I don't have a env file with a declared PORT...
– Macaret
Nov 22 '18 at 9:24
That's why he placed a
||if process.env isn't defined, it takes the3000– Izio
Nov 22 '18 at 9:26
Heroku defines what port it wants to use with environment variable
PORT, it might not be 3000 in most cases– William Chong
Nov 22 '18 at 9:28
Updated with logs after setting list as you said...
– Macaret
Nov 22 '18 at 9:50