🚀 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.1
Install the latest LTS release:
fish nvm install lts/iron
Verify 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.12
Set the local Python version for the project:
bash pyenv local 3.10.12
Verify the Python version:
python --version
4. Create Python Virtual Environment
Create a virtual environment for the project:
Use the Python shim to create a virtual environment:
bash python -m venv .venv
Source the virtual environment (handled by
direnv
):bash source .venv/bin/activate
Upgrade
pip
:bash pip install --upgrade pip
Install project dependencies (e.g., from a
requirements.txt
file):bash pip install -r requirements.txt
Verify the virtual environment and Python version:
which python
python --version
5. 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 .env
Allow direnv
to load the environment:
direnv allow
7. Install Node Project Dependencies
Install all project dependencies based on package.json
:
npm install
8. Verify Dependencies
List local project dependencies:
npm list --depth=0
Check for missing peer dependencies or vulnerabilities:
npm audit
Fix missing peer dependencies:
npm install <package-name> --save-dev
9. Run and Test the Project
Start the development server:
npm start
Build the project:
npm run build
Verify Python setup:
which python
python --version
Workflow Summary
Install NVM and Node versions:
fisher install jorgebucaran/nvm.fish nvm install <version>
Set Node version in
.nvmrc
:12.18.1
Install Python version and create virtual environment:
pyenv install 3.10.12 pyenv local 3.10.12 python -m venv .venv
Activate the environment with
direnv
:direnv allow
Install dependencies:
pip install --upgrade pip pip install -r requirements.txt npm install
Verify 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