0

I have all of the static files in a directory called 'public' which has an index.html file. However when deployed to Heroku the css and javascript files in the public directory are not there. I get 404 errors because they don't exist, yet the files are present in local and there is no error.

In my app.js I have

app.use( express.static( 'public' ) );

When I run heroku run bash the js/css files just aren't there. In addition to that I get this error. I tried

process.env.PWD = process.cwd()
app.use(express.static(process.env.PWD + '/public'));

Because that was a solution I found to a similar error but that doesn't seem to work.

OJGin
  • 1

1 Answers1

0

Try this:

app.use( express.static( __dirname + '/public' ) );

__dirname will resove to the directory your script is in. This will make sure you have a full path to your "public" directory.

mkhanoyan
  • 1,958
  • 18
  • 15
  • I tried that and that didn't seem to change anything. I thought having an index.html file meant that specifying the default route was unnecessary. Thanks though! – OJGin Dec 09 '16 at 20:18
  • Did you commit you JS and CSS files? Heroku will only copy files that are committed.. – mkhanoyan Dec 09 '16 at 20:26
  • Check out the accepted answer [here](http://stackoverflow.com/questions/17212624/deploy-nodejs-on-heroku-fails-serving-static-files-located-in-subfolders). Could it really be an npm version issue... – mkhanoyan Dec 09 '16 at 22:18