0

I have this post-receive script as a git hook when exporting with the following contents

#!/usr/bin/env bash
export NODE_ENV=production
git --work-tree=/home/myusername/app --git-dir=/home/myusername/git checkout -f
cd /home/myusername/app
npm prune
npm install --production
knex migrate:latest

When ssh'd in my server I installed knex globally but it doesn't seem to exist within the bash shell's environment. I lack the knowledge of knowing how they are different. I also noticed my node versions were different. How do I import my user's normal environment?

Mathieu Bertin
  • 425
  • 5
  • 19

1 Answers1

1

To get the names and versions of modules that you have installed globally run:

npm list --global --depth=0

You can then install those modules on the second system with:

npm install --global module_name module_name ...

If you want to install a specific version of Node on the second system you can use nvm or see those answers for details:

This is the first time I see a shebang like that:

#!/usr/bin/env bash

I've seen using /usr/bin/env to find node, python, perl interpreters etc. but never for bash. Usually it's just:

#!/bin/bash

Remember that if you want to run some program from a Bash script (without giving a full path) then it must be in a directory that is in the PATH environment variable.

To see your PATH run:

echo $PATH

Or you can use a full path to a binary in a script:

#!/bin/sh
/full/path/to/something

and then it doesn't need to be in the PATH.

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177
  • What I didn't know is that -g installs it in the node version that youre using. I was using nvm on my server and it got installed under the version I was using. Sourcing nvm in my bash script and then specifying the node version I wanted to use before trying to run knex solved my issue. – Mathieu Bertin Apr 06 '17 at 18:41
  • @MathieuBertin Yes, that's how nvm works. You didn't mention that you use nvm on the server. – rsp Apr 06 '17 at 19:29
  • I lacked the proper understanding of how npm install -g worked. Thank you for your detailed answer. – Mathieu Bertin Apr 06 '17 at 19:47