heroku - Express error when trying to send static file: path must be absolute -


i have code works fine locally, when running in heroku error

var express = require('express') var app = express() var path = require('path') app.use(express.static('public')); var bodyparser = require('body-parser') app.use(bodyparser.urlencoded({   extended: true })); // parse application/json app.use(bodyparser.json()) const portnum = 8080 var port = process.env.port || portnum;  app.get('/', function (req, res) {   res.sendfile('index.html') }) 

however when running in heroku error:

typeerror: path must absolute or specify root res.sendfile

any ideas?

you can absolute path using:

path.join(__dirname, myfilename) 

reference - https://nodejs.org/api/globals.html#globals_dirname


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -