How do I change the root folder that a node module will look for?

957 Views Asked by At

I have a nodejs app. Inside this app, I have a secondapp and I use vhost to use one or other. The problem is: my second app uses a node module that needs a config file (file.json). This module look for this file in the root folder. However, the module is looking at the root folder of the project (the root app), and I want that the module look at the root folder of the SecondApp.

So, the "somenodemodule" is using the "file1.json". But I want to use the "file2.json". How can I change the root folder that the "somenodemodule" will look for?

This is the code of the root app:

var express = require('express');
const app = express();
var http = require('http').Server(app);
var path = require('path');
var connect = require('connect')
var vhost = require('vhost')

var secondapp = require('./secondapp/app');

app.use(vhost('secondapp.com', secondapp));

app.get('/', function(req, res) {
    res.send('Homepage First App');
});

var porta = process.env.PORT || 3000;

http.listen(porta, function(req) {
    console.log("servidor rodando");
})

This is the code of the secondApp:

var express = require('express');
const app = express();
var http = require('http').Server(app);
var somenodemodule = require('somenodemodule');
var path = require('path');

var secondapp = somenodemodule();

app.use(secondapp);

app.get('/', function(req, res) {
    res.send('Homepage Second App');
});

module.exports = app;

And this if my folder structure:

folder structure

0

There are 0 best solutions below