I want to send pretty html using Express 4. How can I user app.locals.pretty
with Express 4? Old syntan doesn't work:
app.locals.pretty = true;
Whole block of code:
app.set('port', process.env.PORT || 1339);
app.set('views', __dirname + '/app/views');
app.set('view engine', 'jade');
app.set('view options', { layout: false });
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(morgan());
app.use(bodyParser());
app.use(methodOverride());
app.use(cookieParser('123'));
app.use(session({
secret: '123',
maxAge: new Date(Date.now() + 3600000),
store: SessionStore
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
var env = process.env.NODE_ENV || 'development';
if ('development' == env) {
app.locals.pretty = true;
}
For pretty printing json, you can set the number indented spaces which should turn on pretty printing:
app.set('json spaces', 2);
Then just do:
res.json({ foo: 'bar', baz: 1234567890 });
Similarly you can app.set('json replacer', function(..){...});
to set the replacer
parameter to JSON.stringify that is used under the hood.
UPDATE: for pretty printing html, I don't think there is anything built into Express for that..
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