Running npm install after a deployment

I am deploying a nodejs site via Octopus Deploy. After the new site has been deployed to the appropriate folder, but before I switch the IIS site to point at the new folder, I need to run “npm install” from the command line.

Can anyone provide an example, in any of the three scripting languages Octopus supports, of how to run a command line as part of the deployment process?

Hi Ross,

Thanks for getting in touch! You can run commands in a predeploy script. You can write the custom script in your package step itself within the web portal, or include it in your package. Our custom scripts docs show these options.
https://octopus.com/docs/deploying-applications/custom-scripts

We have an example in our demo site that you can check out.
https://demo.octopusdeploy.com/app#/projects/phoenix/process/step/d8aa3ec7-493f-45dd-90f2-6a33777cef2e

I hope this helps! Let me know how you go and if you’re hitting any specific errors or issues. :slight_smile:

Best regards,

Kenny

Thanks Kenny. It looks like I was making this a lot harder than it needed to be. In the end my PowerShell script is just this-

$installDirectory = $OctopusParameters[‘Octopus.Action.Package.CustomInstallationDirectory’]
cd $installDirectory
npm install --silent

It’s all working fine now. Appreciate your help.

Hi Ross,

That’s great to hear! Thanks for taking the time to let me know your solution. Don’t hesitate to reach out with any further questions anytime. :slight_smile:

Best regards,

Kenny