FabioEnne
FabioEnne

Reputation: 742

NodeJS: What is the correct way to use different folder?

I'm trying to develop a simple web app and I can't find a way to use different JS files stored in a different folder from the root one, I'll try to explain better.. this is my file structure:

myapp
├── clientSide
│   ├── getDown.js
│   ├── index.html
│   └── uptime.js
├── index.html.save
└── serverSide
    └── myapi.js

The server is running myapi.js and this is chunk of the code:

app.use("/clientSide", express.static(__dirname + '/clientSide'));

console.log(__dirname);

exec("sudo /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'", function(error, stdout, stderr){
        ip = stdout;
                        exports.ipAdd = ip;
                        console.log(ip);
});

now..the problem is that from index.htm I can't import and use the JS files inside the clientSide directory using a simple

<script src="clientSide/getDown.js"></script>

and

<script src="clientSide/uptime.js"></script>

can anyone please edit my piece of code in order to understand? Thanks!

Upvotes: 0

Views: 44

Answers (1)

Darshan
Darshan

Reputation: 1074

In your case you don't need to pass "/clientSide" path to app.use

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

Upvotes: 1

Related Questions