If I do a
res.sendfile('public/index1.html');
then I get a server console warning
express deprecated res.sendfile
: Use res.sendFile
instead
but it works fine on the client side.
But when I change it to
res.sendFile('public/index1.html');
I get an error
TypeError: path must be absolute or specify root to res.sendFile
and index1.html
is not rendered.
I am unable to figure out what the absolute path is. I have public
directory at the same level as server.js
. I am doing the res.sendFile
from with server.js
. I have also declared app.use(express.static(path.join(__dirname, 'public')));
Adding my directory structure:
/Users/sj/test/
....app/
........models/
....public/
........index1.html
What is the absolute path to be specified here ?
I'm using Express 4.x.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…