Skip to content

Instantly share code, notes, and snippets.

@mmende
Last active November 18, 2021 23:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmende/2c10dd6161bc75120dbf153098caa48d to your computer and use it in GitHub Desktop.
Save mmende/2c10dd6161bc75120dbf153098caa48d to your computer and use it in GitHub Desktop.
Install app from an npm registry
#!/bin/bash
# Installs an app from a npm registry into a specific directory
APP=$1
TARGET=$2
# Assure we have both parameters
if [ -z $APP ] || [ -z $TARGET ]; then
echo "Usage: $0 my-node-app /some/install/path/my-node-app"
fi
# Resolve stuff like ../
TARGET=$(realpath $TARGET)
echo "Installing $APP at $TARGET..."
# Whereas npm v6 returns the fetched tarball name,
# npm v7+ won't do that, therefore we use a custom directory
# with wildcard pattern to extract the app
rm -rf /tmp/__install_app
mkdir -p /tmp/__install_app
cd /tmp/__install_app
npm pack $APP
tar xvf *.tgz
mv package $TARGET
cd $TARGET
rm -rf /tmp/__install_app
# Install
NODE_ENV=production npm install --production
@mmende
Copy link
Author

mmende commented Oct 22, 2021

Example usage

To e.g. install some-package to package-installation under the current directory:

bash <(curl -sL https://gist.githubusercontent.com/mmende/2c10dd6161bc75120dbf153098caa48d/raw/installNodeApp.sh) some-package ./package-installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment