how to get homeUrl in Console application in yii2

We have to setup a cron job for our project. Whenever we call ApplicationConfigs component from the console command, the code throws below error -

Exception ‘yii\base\UnknownPropertyException’ with message ‘Getting unknown property: yii\console\Application::homeUrl’

The code is Yii::$app->homeUrl.’/js/’ where we try to set path for js folder.

Is there any way we can get Yii::$app->homeUrl in console? Other component files are running properly from console commands.

In CLI you don’t have access to all $_SERVER variables like you do in the WEB, that’s the reason why yii can’t generate the home url for you. You shouldn’t even need to call that property, at all, instead maybe store the website url in the app params and access those.