'How to find where an application got installed in linux using nodejs

I installed a server on linux. The installation files gets installed under /opt/AppName/ while the service is under /etc/systemd/system/. I need to get the path of a folder 'cert' which is under /opt/AppName when the server starts. Now the process tries to look under current working directory or the root which obviously fails. How do I get the location where the install files are present? Have tried:

const dircert = 'cert'
const certificateDirWin = path.resolve(`${process.cwd()}`, dircert)

and

const certificateDir = path.resolve(__dirname, dircert)

None of these work. However if I hardcode

const certificateDirLin = path.resolve('/opt/AppName', dircert)

it works. How do I get rid of the harcoded path.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source