Automatic deployment commands for Node.js applications

1 minute read

When projects primarily using webpack and Node.js are deployed and updated, it is necessary to run build scripts. This allows us to exclude compiled files from the source code. It also allows to compile according the environment (for example, files can be compiled differently for a development environment and a production environment).

To achieve this on Plesk with Phusion Passenger, I use the following commands:

export PATH="$PATH:/opt/plesk/node/16/bin" && npm install --scripts-prepend-node-path > npm.log 2>&1
export PATH="$PATH:/opt/plesk/node/16/bin" && npx webpack build --config ./webpack.config.js > npx-webpack.log 2>&1
export PATH="$PATH:/opt/plesk/node/16/bin" && npx grunt-cli buildcss > npx-css.log 2>&1
touch ./tmp/restart.txt

Note that:

  • You must choose the version of Node.js to use. In the previous example, version 16 was chosen.
  • Output messages are redirected to log files, rather than being displayed in the Plesk interface.

Optionally, when patches must be applied to certain packages and patch-package is used, the following command can be added:

export PATH="$PATH:/opt/plesk/node/16/bin" && npx patch-package

Once configured in the interface, this is what it looks like.

Visual example in Plesk