🚀 Node.js and Python Project Setup Cheatsheet
1. Install nvm.fish for Fish Shell
Install nvm.fish to manage Node versions natively in Fish shell:
fisher install jorgebucaran/nvm.fish
2. Install Required Node.js Versions
Install the specific Node versions needed for your project.
Install a specific version:
fish nvm install 12.18.1Install the latest LTS release:
fish nvm install lts/ironVerify installed versions:
fish nvm ls
3. Install Required Python Version
If the correct Python version is not available, use pyenv to install it:
Install a specific Python version:
bash pyenv install 3.10.12Set the local Python version for the project:
bash pyenv local 3.10.12
Verify the Python version:
python --version4. Create Python Virtual Environment
Create a virtual environment for the project:
Use the Python shim to create a virtual environment:
bash python -m venv .venvSource the virtual environment (handled by
direnv):bash source .venv/bin/activateUpgrade
pip:bash pip install --upgrade pipInstall project dependencies (e.g., from a
requirements.txtfile):bash pip install -r requirements.txt
Verify the virtual environment and Python version:
which python
python --version5. Create a .nvmrc File
The .nvmrc file specifies the Node version required for your project.
Example .nvmrc file:
12.18.1
6. Create .envrc for Project Setup
Set up Node.js, Python virtual environments, and environment variables using direnv.
.envrc:
# Set NVM directory
export NVM_DIR="$HOME/.local/share/nvm"
# Use Node.js version specified in .nvmrc
NODE_VERSION=$(cat .nvmrc)
NODE_BIN_PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin"
if [ -d "$NODE_BIN_PATH" ]; then
export PATH="$NODE_BIN_PATH:$PATH"
else
echo "Node version $NODE_VERSION is not installed. Run: nvm install $NODE_VERSION"
exit 1
fi
# Activate Python virtual environment
source .venv/bin/activate
# Load environment variables from .env
dotenv .envAllow direnv to load the environment:
direnv allow7. Install Node Project Dependencies
Install all project dependencies based on package.json:
npm install8. Verify Dependencies
List local project dependencies:
npm list --depth=0Check for missing peer dependencies or vulnerabilities:
npm auditFix missing peer dependencies:
npm install <package-name> --save-dev9. Run and Test the Project
Start the development server:
npm startBuild the project:
npm run buildVerify Python setup:
which python
python --versionWorkflow Summary
Install NVM and Node versions:
fisher install jorgebucaran/nvm.fish nvm install <version>Set Node version in
.nvmrc:12.18.1Install Python version and create virtual environment:
pyenv install 3.10.12 pyenv local 3.10.12 python -m venv .venvActivate the environment with
direnv:direnv allowInstall dependencies:
pip install --upgrade pip pip install -r requirements.txt npm installVerify and run:
npm list --depth=0 npm start python --version
✅ Done: Your Node.js and Python project environment is ready!
Additional notes
Cleanout and re-install node packages
rm -rf node_modules package-lock.json
npm install
Cleanout python packages
rm -rf .venv
Unsource the environment and re-create with the correct python (see above)
python -m venv .venv