Update: This issue is related to azure-function-express
I am using express.js and azure-function-express. Below is the piece of code I am using to try to return a package.zip
file to the call using res.sendFile()
var express = require('express');
var router = express.Router();
router.get('/', function (req, res) {
console.log('Sending signed certificate');
var options = {
root: __dirname + '/public/'
};
var fileName = 'package.zip';
res.sendFile(fileName, options, function (err) {
if (err) {
console.log(err);
next(err);
} else {
console.log('Sent:', fileName);
}
});
})
module.exports = router
However, when I run it, I get the following error:
TypeError: Cannot read property 'length' of null
[10/11/2018 1:19:21 AM] Sending signed certificate
[10/11/2018 1:19:25 AM] Worker 97959602-60bb-4608-9f3b-8696a2ee7dd6 uncaught exception: TypeError: Cannot read property 'length' of null[10/11/2018 1:19:25 AM]
[10/11/2018 1:19:25 AM] Worker 97959602-60bb-4608-9f3b-8696a2ee7dd6 exited with code 1
[10/11/2018 1:19:25 AM] at ServerResponse._send (_http_outgoing.js:232:33)
[10/11/2018 1:19:25 AM] at write_ (_http_outgoing.js:667:15)
[10/11/2018 1:19:25 AM] at ServerResponse.write (_http_outgoing.js:617:10)
[10/11/2018 1:19:25 AM] at ReadStream.ondata (_stream_readable.js:639:20)
[10/11/2018 1:19:25 AM] at emitOne (events.js:116:13)
[10/11/2018 1:19:25 AM] at ReadStream.emit (events.js:211:7)
[10/11/2018 1:19:25 AM] Language Worker Process exited.
[10/11/2018 1:19:25 AM] at addChunk (_stream_readable.js:263:12)
[10/11/2018 1:19:25 AM] node exited with code 1
Not able to figure out what is wrong in my code.
Interesting observations
- The code does not reach if (err) line at all
- The browser gets hung, waiting for a response indefinitely
Thanks in advance.