As @Josir suggests, I have used nodeenv
in the past but I had an issue when I wanted to have the node modules inside the venv
folder of the project as explained in this question.
In short putting a package.json
in venv
results in not being able to use npx ...
unless it is run from the venv
folder whereas putting package.json
in venv/lib
and running npm install
from there results in being able to use npx ...
from any folder in the project.
This is due to the NODE_PATH
environment variable being set to <myproject>/venv/lib/node_modules
.
I created a script to automate this which in substance does:
python -m venv venv
source venv/bin/activate
pip install requirements.txt
cp package.json venv/lib
cd venv/lib
nodeenv -p
npm install --no-optional