0

i have nodejs config file(backend) in which some configuration data is defined:

module.exports = {
    product: {
        name: 'Event'
    },
    server: {

            host: '0.0.0.0',
            port: 8000
    },
    database: {
        host: '127.0.0.1',
        port: 27017,
        db: 'EventExchange',
        username: '',
        password: ''
    },
    key:{
        privateKey: 'dufediioeduedhn',
        tokenExpiry: 1*30*1000*60   //1 hour
    },
    admin:{
        "username" : "admssin",
        "password" : "adminss123",
        "scope"    : "adamssin"
    }
};

i have to access port and host parameter in angular(client side). how is it posssible ? Thanks!

2
  • how??? explain whats the problem, what have you tried. Commented Feb 5, 2015 at 11:38
  • i need port and host from configuration file in client side so that we don't need to change port and host manually every place in code. do if i will change port and host parameter in config file,it will automatically get change entire web applicdation. Commented Feb 5, 2015 at 11:48

1 Answer 1

4

You have to send them in a response (by sending JSON).

After that you can parse it using Json.parse.

For ex : At node side create a rest api

 app.get('/getConfig/', function (req, res, next) {
//NOW FETCH YOUR CONFIG
//PUT THE CONFIG IN JSON
var myConfig={port:database.port,host:database.hoat}
res.json(myConfig);
});

Now call this api from your AngularJs code by using $http

for ex:

$http.get("/getConfig").success(function(data))
{
console.log(data);
console.log(data.port);
console.log(data.host);
}

Hope this will help you !! Cheers :)

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.