0

there, I have a little problem with node.js and express on heroku. I have a node.js server that loads up my index.html page and other resources:

process.env.PWD = process.cwd();
var express = require("express");
var fs = require("fs-extra");
var app = express();
app.use(express.static(process.env.PWD+"/Anos"));
app.use(process.env.PWD +"/Applications", express.static(process.env.PWD + '/Anos/Applications'));

app.get(process.env.PWD+"/Anos",function(req,res) {
});
console.log("hello bitche");
var server = app.listen(process.env.PORT || 8080,function() {
    console.log("Project Alexander listening on port 8080!");
});
global.io = require("socket.io").listen(server);
var login = require("./local_modules/login.js");
var saveFiles = require("./local_modules/fileFolderSave.js");
global.io.sockets.on("connection",function(client) {
    login(client,global.io,fs,process.env.PWD);
    saveFiles(client,global.io,fs,process.env.PWD);
});

This works grand on localhost, but when I deploy it to heroku from dropbox it only loads certain things like css and js files, all of which are in sub directories. The things that aren't loaded are the icon.png files from the folders in the applications folder. Dir structure:

Anos/
  index.html
  css/
     Taskbar/
     Desktop/
     Infopane/
  js/
     Taskbar/
     Desktop/
     Infopane/
  Applications/
     App1/
        icon.png
     App2/ etc..
        icon.png
  userData/
  users/
  images/

The app here) (type

an

and click login and check the console for 404 errors. Let me know if you need anything else. Any ideas? What can i change to get rid of these errors and load everything properly? Thanks in advance!

ERRORS: image

0

1 Answer 1

0

I have once had this problem. The way I solved it was to rename my public folder as public and set it as public like this

var path = require('path')

process.env.PWD = process.cwd();
app.use(express.static(path.join(process.env.PWD, 'public')));

I hope this helps

3
  • Excuse me for not knowing but the public folder is the one the server.js file is in isn't it? Jun 30, 2017 at 21:34
  • sure it works, though I had later tried it before seeing this. Thanks anyway. i appreciate
    – Jalasem
    Jul 2, 2017 at 23:38
  • Still won't work, i'm thinking of changing to something like Azure anyway. Thanks for the help. +Jalasem Jul 3, 2017 at 2:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .