Node Express RESTful API default engine for error handling
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am working on a set of RESTful API services built using Node.js Express, and when it gets an error a stack-trace follows preceded with:
Error: No default engine was specified and no extension was provided.
I have read several previous Stack Overflow articles about expected code within app.js for handling errors:
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
However, for default engine, the StackOverflow recommendations focus on using Vue with Jade.
This is an internal RESTful API service and I would prefer not to add a default engine outputting error response in Jade.
Recommendations?
This is an example stack-trace from my RESTful API service:
[09:22:42] info: GET /api/v1/archives/google/folders 401 130ms
Error: No default engine was specified and no extension was provided.
at new View (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/view.js:61:11)
at Function.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/response.js:1008:7)
at /Users/jeff/github/jeff00/act-archive/app.js:137:7
at Layer.handle_error (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/router/layer.js:71:5)
node.js rest express error-handling
add a comment |
I am working on a set of RESTful API services built using Node.js Express, and when it gets an error a stack-trace follows preceded with:
Error: No default engine was specified and no extension was provided.
I have read several previous Stack Overflow articles about expected code within app.js for handling errors:
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
However, for default engine, the StackOverflow recommendations focus on using Vue with Jade.
This is an internal RESTful API service and I would prefer not to add a default engine outputting error response in Jade.
Recommendations?
This is an example stack-trace from my RESTful API service:
[09:22:42] info: GET /api/v1/archives/google/folders 401 130ms
Error: No default engine was specified and no extension was provided.
at new View (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/view.js:61:11)
at Function.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/response.js:1008:7)
at /Users/jeff/github/jeff00/act-archive/app.js:137:7
at Layer.handle_error (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/router/layer.js:71:5)
node.js rest express error-handling
add a comment |
I am working on a set of RESTful API services built using Node.js Express, and when it gets an error a stack-trace follows preceded with:
Error: No default engine was specified and no extension was provided.
I have read several previous Stack Overflow articles about expected code within app.js for handling errors:
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
However, for default engine, the StackOverflow recommendations focus on using Vue with Jade.
This is an internal RESTful API service and I would prefer not to add a default engine outputting error response in Jade.
Recommendations?
This is an example stack-trace from my RESTful API service:
[09:22:42] info: GET /api/v1/archives/google/folders 401 130ms
Error: No default engine was specified and no extension was provided.
at new View (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/view.js:61:11)
at Function.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/response.js:1008:7)
at /Users/jeff/github/jeff00/act-archive/app.js:137:7
at Layer.handle_error (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/router/layer.js:71:5)
node.js rest express error-handling
I am working on a set of RESTful API services built using Node.js Express, and when it gets an error a stack-trace follows preceded with:
Error: No default engine was specified and no extension was provided.
I have read several previous Stack Overflow articles about expected code within app.js for handling errors:
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
However, for default engine, the StackOverflow recommendations focus on using Vue with Jade.
This is an internal RESTful API service and I would prefer not to add a default engine outputting error response in Jade.
Recommendations?
This is an example stack-trace from my RESTful API service:
[09:22:42] info: GET /api/v1/archives/google/folders 401 130ms
Error: No default engine was specified and no extension was provided.
at new View (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/view.js:61:11)
at Function.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/response.js:1008:7)
at /Users/jeff/github/jeff00/act-archive/app.js:137:7
at Layer.handle_error (/Users/jeff/github/jeff00/act-archive/node_modules/express/lib/router/layer.js:71:5)
node.js rest express error-handling
node.js rest express error-handling
edited Jan 4 at 17:26
Jeff Tanner
asked Jan 4 at 17:17
Jeff TannerJeff Tanner
47111
47111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You are using res.render
calls because of which Express expects a rendering engine to be set for the application. Remove the res.render
and do something like res.json
and this error won't come up.
Hi @faizuddin-mohammed. I have tried usingres.json
before, recommend by another StackOverflow article and I get a warning:express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.
– Jeff Tanner
Jan 4 at 17:29
1
Oh, just use theres.status(404).json(errObj)
and get rid of all the otherres.*
calls.
– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just usingres.status(404).json(errObj)
, however, I get[ERR_HTTP_HEADERS_SENT]
.
– Jeff Tanner
Jan 4 at 19:03
Did you remove the otherres.status
call?
– Faizuddin Mohammed
Jan 5 at 4:57
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%2f54043393%2fnode-express-restful-api-default-engine-for-error-handling%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 are using res.render
calls because of which Express expects a rendering engine to be set for the application. Remove the res.render
and do something like res.json
and this error won't come up.
Hi @faizuddin-mohammed. I have tried usingres.json
before, recommend by another StackOverflow article and I get a warning:express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.
– Jeff Tanner
Jan 4 at 17:29
1
Oh, just use theres.status(404).json(errObj)
and get rid of all the otherres.*
calls.
– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just usingres.status(404).json(errObj)
, however, I get[ERR_HTTP_HEADERS_SENT]
.
– Jeff Tanner
Jan 4 at 19:03
Did you remove the otherres.status
call?
– Faizuddin Mohammed
Jan 5 at 4:57
add a comment |
You are using res.render
calls because of which Express expects a rendering engine to be set for the application. Remove the res.render
and do something like res.json
and this error won't come up.
Hi @faizuddin-mohammed. I have tried usingres.json
before, recommend by another StackOverflow article and I get a warning:express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.
– Jeff Tanner
Jan 4 at 17:29
1
Oh, just use theres.status(404).json(errObj)
and get rid of all the otherres.*
calls.
– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just usingres.status(404).json(errObj)
, however, I get[ERR_HTTP_HEADERS_SENT]
.
– Jeff Tanner
Jan 4 at 19:03
Did you remove the otherres.status
call?
– Faizuddin Mohammed
Jan 5 at 4:57
add a comment |
You are using res.render
calls because of which Express expects a rendering engine to be set for the application. Remove the res.render
and do something like res.json
and this error won't come up.
You are using res.render
calls because of which Express expects a rendering engine to be set for the application. Remove the res.render
and do something like res.json
and this error won't come up.
answered Jan 4 at 17:22
Faizuddin MohammedFaizuddin Mohammed
1,84631525
1,84631525
Hi @faizuddin-mohammed. I have tried usingres.json
before, recommend by another StackOverflow article and I get a warning:express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.
– Jeff Tanner
Jan 4 at 17:29
1
Oh, just use theres.status(404).json(errObj)
and get rid of all the otherres.*
calls.
– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just usingres.status(404).json(errObj)
, however, I get[ERR_HTTP_HEADERS_SENT]
.
– Jeff Tanner
Jan 4 at 19:03
Did you remove the otherres.status
call?
– Faizuddin Mohammed
Jan 5 at 4:57
add a comment |
Hi @faizuddin-mohammed. I have tried usingres.json
before, recommend by another StackOverflow article and I get a warning:express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error:Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.
– Jeff Tanner
Jan 4 at 17:29
1
Oh, just use theres.status(404).json(errObj)
and get rid of all the otherres.*
calls.
– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just usingres.status(404).json(errObj)
, however, I get[ERR_HTTP_HEADERS_SENT]
.
– Jeff Tanner
Jan 4 at 19:03
Did you remove the otherres.status
call?
– Faizuddin Mohammed
Jan 5 at 4:57
Hi @faizuddin-mohammed. I have tried using
res.json
before, recommend by another StackOverflow article and I get a warning: express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.– Jeff Tanner
Jan 4 at 17:29
Hi @faizuddin-mohammed. I have tried using
res.json
before, recommend by another StackOverflow article and I get a warning: express deprecated res.json(status, obj): Use res.status(status).json(obj) instead
, and an error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
. Thank you for your response.– Jeff Tanner
Jan 4 at 17:29
1
1
Oh, just use the
res.status(404).json(errObj)
and get rid of all the other res.*
calls.– Faizuddin Mohammed
Jan 4 at 17:40
Oh, just use the
res.status(404).json(errObj)
and get rid of all the other res.*
calls.– Faizuddin Mohammed
Jan 4 at 17:40
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just using
res.status(404).json(errObj)
, however, I get [ERR_HTTP_HEADERS_SENT]
.– Jeff Tanner
Jan 4 at 19:03
Hi @faizuddin-mohammed. Yes, in my last comment and prior to your comment, I had tried just using
res.status(404).json(errObj)
, however, I get [ERR_HTTP_HEADERS_SENT]
.– Jeff Tanner
Jan 4 at 19:03
Did you remove the other
res.status
call?– Faizuddin Mohammed
Jan 5 at 4:57
Did you remove the other
res.status
call?– Faizuddin Mohammed
Jan 5 at 4:57
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%2f54043393%2fnode-express-restful-api-default-engine-for-error-handling%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