Kill the npm install ant with a time bomb!

Before starting off on the actual blog article, here are some of the concepts/diagrams to explain about a Next JS application running in Docker container:


Understandably, the container provides the environment for the application. More about the folders within a container can be found here

Here is a screen shot of the folders with time stamps to confirm the order of deployment:


Now, off to the actual article:

As part of setting up the Sitecore Demo Edge Site locally, one of the issues with first-time site startup  is blogged here. I also blogged another issue/solution with regard to why node_modules folder wasn't created. I decided to put both together and as a result, this blog article! So, there are these two options:

1. As one of the first things in up.ps1, check for node_modules folder in the relevant location, if not present,  alert the user to install the node_modules manually. I prefer the check and install instead of forcing an install every-time!


######################################################

$nodeModules=".\Website\src\rendering\node_modules\*"

$nodeModulesExist=Test-Path $nodeModules

if ($nodeModulesExist -eq $False) {       

        Write-Host "Just installed node modules, restart PowerShell in new prompt and restart up.ps1 execution!" -ForegroundColor Red

      exit 0

}

######################################################


2. Apart from the above check, perform the install automatically as one of the first steps in the up.ps1 script:

######################################################

$nodeModules=".\Website\src\rendering\node_modules\*"

$nodeModulesExist=Test-Path $nodeModules

if ($nodeModulesExist -eq $False) {       

      Push-Location .\Website\src\rendering

      npm install --force

      Pop-Location

      Write-Host "Just installed node modules, restart PowerShell in new prompt and restart up.ps1 execution!" -ForegroundColor Red

      exit 0

}

######################################################

Some testing in case of option 2:

First run of up.ps1 installs node modules and provides the necessary alert for the user:


Now, as per the message, restart up.ps1 execution in new PS prompt and first time load is successful!


Like any skill, it is necessary to hone coding/analysis as a skill by taking short steps on a daily basis. My articles are notes of my daily code attempts!

Comments

Popular Posts