Enonic XP 6.8.x - How to read value from properties file

Enonic version: 6.8
OS: Centos 6

Hi,

I have a properties file src/main/resources/site/server-settings.properties which contains some properties such as
url=www.domain.com
key=xxxxxx

How can I get these value with serverside js?

Thanks
Thanh

Hi Thanh,

This is a typical use case for the io library. Require /lib/xp/io, then getResource() with the path to your properties file.

Best wishes,
Bjørnar

From what I see this is a file within an app? Config property files are commonly placed in the config/ directory named according to your app. The settings will automatically be available in the app context I believe

Hi,

Consider using app config files accesible from the global app.config object.
http://xp.readthedocs.io/en/6.8/developer/ssjs/global-objects.html#app

It requires you to move and rename your file, but other than that the format will be the same.

Thanks very much for amazing answers. I go for the app.config option.
If I have hundred of apps deployed on one enonic instance, would this affect the performance?

Hi again,

In theory it would affect performance, since each app might have filters and mappings that needs to run on each request. But it all depends on the apps. We don’t even have 100 apps so we have not tested this. So we advice you to proparly performance test such a setup as there might be small things you do in the code in many of the apps that affects the permonca slightly, adding to a big slowdown in total.

Working with 10-20 “normal” apps on a site does not affect performance in a noticable way.

One thing is sure - using app configuration files will not affect performance in any way. Adding 100s of apps to a site might or might not affect performance depending on what the apps do. Anyways this sounds like a highly theoretical use case :slight_smile: