Read system properties from JS

Enonic version: 6.13.1
OS: Centos 6

Hi,

I have a property called db.admin.url=www.demo.no in system.properties
How can I get this property within JS?

Thanks for any help.

I suppose you mean in the XP_HOME/config/system.propeties file.
Is there a reason to set it in that file?

It would be better to set the property in the config file for your application.

You can create a file with the name of you application key, and extension '.cfg'

Example XP_HOME/config/com.enonic.myapp.cfg

db.admin.url=www.demo.no

Then in your Javascript controller code you can just get the value like this:

var dbAdminUrl = app.config['db.admin.url'];

See documentation here: http://xp.readthedocs.io/en/stable/developer/ssjs/global-objects.html#app

1 Like

Hi,

The reason I set it in the XP_HOME/config/system.propeties file is that this property is the same for all applications in the installation,

There is no javascript api to access the system.properties file. It was not meant to be used for shared application properties. It’s for internal XP configuration.

You could try to use this library to access the file system: https://market.enonic.com/vendors/rbrastad/file-system-library
Or make a new library in Java.

1 Like