My goal is to port my existing Node-Express-Pug-Mongo website onto Amazon Web Services, but I'm running into an error with rendering Pug files on Lambda. Whenever I attempt to run res.render
, the page shows this: {"message": "Internal server error"}
after a timeout of 3000 milliseconds (from viewing the CloudWatch console).
I've tried throwing console.log
everywhere to get more information on what is causing the error, but to no avail.
res.send
works with textres.sendFile
works with the Pug file that I am trying to use in the functionres.render
accepts a callback input, which I have attempted to use to catch errors, but no logs exist on the console.- I've tried different ways of inputting the pug file, as you can see for the five different
get
URLs. All of them do the same thing. - I've tried changing to Jade, but I get the same issues.
- NOTE: On a local server, the syntax in render1 and render3 are the ones that work.
- ALSO: On the local server, using callbacks does cause the function to hang. I have attempted this with and without callbacks, and the issue is the same.
'use strict'
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const router = express.Router();
app.set('view engine', 'pug');
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
app.set('views', path.join(__dirname, 'views'));
router.get('/sendfile', function(req, res){
res.sendFile(__dirname+"/views/test.pug");
});
router.get('/sendtext', function(req, res){
res.send('hello!');
});
router.get('/render1', function(req, res){
res.render('test', {}, function(err){
console.log(err);
});
});
router.get('/render2', function(req, res){
res.render('.test', {}, function(err){
console.log(err);
});
});
router.get('/render3', function(req, res){
res.render('./test', {}, function(err){
console.log(err);
});
});
router.get('/render4', function(req, res){
res.render('./views/test', {}, function(err){
console.log(err);
});
});
router.get('/render5', function(req, res){
res.render(__dirname+'/views/test', {}, function(err){
console.log(err);
});
});
app.use('/', router);
// Export your express server so you can import it in the lambda function.
module.exports = app;
None of these render functions work. It always times out after 3 seconds and returns {"message": "Internal server error"}
. I've tried everything I could think of. Is this an Express issue? Do I have to do something different to configure Pug? It works exactly as expected when I use the exact same module on a local Node.js server.