parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

TypeError: res.sendFile is not a function

Open jaydeep82 opened this issue 10 years ago • 6 comments

For implementation related questions or technical support, please refer to the stackoverflow community.

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!

Environment Setup

Heroku + MongoLab

Steps to reproduce

I have deployed parse on Heroku and I'm able to call the all cloud functions.

When call with '/' it's working showing 'I dream of being a web site.' But when I call https://myapp-dev2.herokuapp.com/test in browser, it showing error

app.get('/', function(req, res) {
  res.status(200).send('I dream of being a web site.');
});

app.get('/test', function(req, res) {
   //res.sendFile('/app/public/index.html');
   res.sendFile('public/index.html', { root: __dirname });
});

Logs/Trace

2016-03-18T15:12:54.734560+00:00 app[web.1]: TypeError: res.sendFile is not a function
2016-03-18T15:12:54.734603+00:00 app[web.1]:     at Object.handle (/app/index.js:68:8)
2016-03-18T15:12:54.734613+00:00 app[web.1]:     at next_layer (/app/node_modules/express/lib/router/route.js:103:13)
2016-03-18T15:12:54.734614+00:00 app[web.1]:     at Route.dispatch (/app/node_modules/express/lib/router/route.js:107:5)
2016-03-18T15:12:54.734615+00:00 app[web.1]:     at /app/node_modules/express/lib/router/index.js:205:24
2016-03-18T15:12:54.734615+00:00 app[web.1]:     at Function.proto.process_params (/app/node_modules/express/lib/router/index.js:269:12)
2016-03-18T15:12:54.734616+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/index.js:199:19)
2016-03-18T15:12:54.734616+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/index.js:176:38)
2016-03-18T15:12:54.734617+00:00 app[web.1]:     at next (/app/node_modules/express/lib/router/index.js:176:38)
2016-03-18T15:12:54.734617+00:00 app[web.1]:     at Layer.expressInit [as handle] (/app/node_modules/express/lib/middleware/init.js:23:5)
2016-03-18T15:12:54.734618+00:00 app[web.1]:     at trim_prefix (/app/node_modules/express/lib/router/index.js:240:15)

jaydeep82 avatar Mar 18 '16 15:03 jaydeep82

From the express docs: res.sendFile() is supported by Express v4.8.0 onwards

I assume this is your issue, as it's not related to parse-server.

gfosco avatar Mar 18 '16 17:03 gfosco

You can update your package json to require a newer version of express.

gfosco avatar Mar 18 '16 17:03 gfosco

This was the fix!!! glad I found this.

mdere avatar Jan 13 '17 17:01 mdere

Update version to 4.8.0. Still getting error.

sudheerkaushik avatar Jan 05 '18 11:01 sudheerkaushik

const express=require('express'); const mysql=require('mysql2') const path = require('path');

const app=express();

const db=mysql.createConnection({ host:'localhost', user:'root', password:'root', database:'school' });

db.connect((err)=>{ if(err){ console.error('error connecting',err); process.exit(1); } console.log('connected as id'+db.threadId); });

app.use(express.urlencoded({extended:true}));

const validateInput=(input)=>{ const trimmedInput=input.trim(); if (trimmedInput.length===0){ throw new error('input cannot be empty');
} return mysql.escape(trimmedInput); };

app.post('/submit',(req,res) => { try{ const username=validateInput(req.body.username); const query="INSERT INTO table1(sname) VALUES (?)"; db.query(query,[username],(err,results)=>{ if(err){ console.error('error runing query',err); res.status(500).send('error inserting data'); } else{ res.send('inserted data ${username}'); } }); } catch(error){ console.error('validatinginput',error); res.status(400).send('invalid input'); } });

app.get('/',(res,req)=>{ res.sendfile(path.join(__dirname+'/index.html')); }); const port = 9000; app.listen(port, () => { console.log(Server running on port ${port}); });

chansudh02 avatar Aug 30 '24 04:08 chansudh02

what error in this node js file

chansudh02 avatar Aug 30 '24 04:08 chansudh02