0

I ran a simple NodeJS and Express server on my Windows 10 development machine

var express = require('express');
var app = express();

app.use(express.static('app'));
app.use('/bower_components', express.static('bower_components'));

app.listen(3000, function () {
    console.log("Listening on :3000");
});

This works, however when I tried to upload it on my Linux (Ubuntu 14.04) box, only files which are present directly under /app will get served, and nothing from the subfolders.

On the linux machine, I noticed I was running node version v0.10 so I updated to v4.5.0. My windows machine runs v4.4.4.

I had an idea it might be related to permissions, so I tried setting those, but to no avail.

The file structure looks like this

├───api
├───app
│   ├───assets
│   │   ├───css
│   │   └───images
│   └───scripts
│       ├───auth
│       ├───directives
│       ├───filters
│       ├───home
│       ├───i18n
│       └───services
├───bower_components

Have anyone been through the same sort of issue?

4
  • can you post the actual file structure of your app? Commented Sep 1, 2016 at 19:36
  • @DaveV Updated now Commented Sep 1, 2016 at 19:40
  • When you use chmod and chown on Linux, use the -R flag so that the permissions recurse into the sub directories. Commented Sep 1, 2016 at 19:41
  • 1
    If all of the directory permissions look good, check the permissions of the Node script. Commented Sep 1, 2016 at 19:43

1 Answer 1

1

I think you put everything in files good, so only issue, that can be painfull for nodeJS serving like you want is that path is not specified.

https://expressjs.com/en/starter/static-files.html

If you do app.use(express.static('app')); the dierectory app is injected at / directory (or execution folder of nodeJs installation in extreme case). The only thing that comes to my mind is to add __dirname + '/app' before express.static: app.use(__dirname + '/app', express.static('app'));

__dirname is a nodeJS variable in the module's scope that contains the name of the directory that the currently executing script resides in


If that is changing something try this to match everything: What is the difference between __dirname and ./ in node.js?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.