Last active
November 15, 2016 11:26
-
-
Save vitalymak/56dcbbd041148db545701fba24674fde to your computer and use it in GitHub Desktop.
Fork spawn/exec new instance of node difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
. ~/.nvm/nvm.sh | |
nvm install 4.6.2 >/dev/null 2>&1 | |
nvm install 6.9.1 >/dev/null 2>&1 | |
echo 'console.log("Forked child: " + process.version)' > to-fork.js | |
# prints v6.9.1 | |
node -v | |
# prints v4.6.2 | |
~/.nvm/versions/node/v4.6.2/bin/node -v | |
# prints v4.6.2 | |
~/.nvm/versions/node/v4.6.2/bin/node -e "require('child_process').fork('to-fork.js')" | |
echo "Start v4.6.2 node and spawn new instance of node, doesn't matter exec or spawn... Prints v6.9.1 two times." | |
~/.nvm/versions/node/v4.6.2/bin/node -p -e "require('child_process').execSync('node -v').toString()" | |
~/.nvm/versions/node/v4.6.2/bin/node -p -e "require('child_process').spawnSync('node',['-v']).stdout.toString()" | |
rm to-fork.js | |
# Full output: | |
# v6.9.1 | |
# v4.6.2 | |
# Forked child: v4.6.2 | |
# Start v4.6.2 node and spawn new instance of node, doesn't matter exec or spawn... Prints v6.9.1 two times. | |
# v6.9.1 | |
# v6.9.1 | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment