Does anyone have a concrete example of having Node.js in a virtual environment and then using it in WebStorm?

I now know one can't create a virtual environment (VENV) using WebStorm, so apparently the only option available for creating a VENV for a Node.js application is 'nodeenv'.

Has anyone already had success using nodeenv to create a VENV for Node.js and then using that VENV as part of a WebStorm-based project? If so, would you please outline the steps taken to use a VENV with WebStorm?

2 comments
Comment actions Permalink

I'd suggest posting this at stackoverflow.com

0
Comment actions Permalink

Using WebStorm2021.2 on Ubuntu 18.04.

So...I figured it out!  Here are the steps:

1. Installed python-based virtualenv using: sudo apt-get install virtualenv
2. Open WebStorm
     1) Left-click on ‘New Project’ button
     2) Navigate to directory where you want to put your project
     3) Left-click on ‘New Folder’ icon
     4) Type in the name of your project
     5) Left-click ‘Ok’
     6) Left-click ‘Create’
3. Open terminal in WebStorm
     1) ‘(base)’ will be showing on the left
     2) type ‘vitrtualenv wrapper_env (but one may type any name to replace ’wrapper_env' for the virtual environment)
     3) type '. wrapper_env/bin/activate
     4) ‘(wrapper_env) (base)’ will be showing on the left (required to install and use nodeenv)
     5) type ‘pip install nodeenv’
          1- Successfully installed nodeenv-1.6.0
     6) type ‘nodeenv nodejs_env’ (but one may type any name to replace ’nodejs_env' for the virtual environment)
          1- * Install prebuilt node (16.6.2) ..... done. (The latest node and npm versions are automatically installed)
     7) type ‘. nodejs_env/bin/activate’
     8) ‘(nodejs_env) (wrapper_env) (base)’ will be showing on the left
     9) type ‘node -v’ to verify node
          1- v16.6.2
    10) type ‘npm -v’ to verify node package manager
          1- 7.20.3
    11) Change settings in WebStorm by: (must be done whenever a new nodeenv environment is created)
          1- Setting>Languages & Frameworks>Node.js and NPM
               1> Left-click on drop-down arrow on right side of ‘Node interpreter:’ line
                    1. Left-click on ‘Add...’
                    2. Left-click on ‘Add Local...’ and navigate to where the ‘node’ interpreter is within deep_env/bin
              2> The ‘Package manager:’ line should be automatically updated with the compatible npm
   12) Deactivate both virtual environments by:
         1- Type ‘deactivate_node’ (deactivates nodejs_env)
              1> ‘(wrapper_env) (base)’ will be showing on the left
         2- Type ‘deactivate’ (deactivates wrapper_env)
              1> ‘(base)’ will be showing on the left
  13) Close project
  14) Open project having a nodeenv virtual environment already created
  15) Open terminal in WebStorm:
        1- (base) will be showing on the left
        2- type ‘. nodejs_env/bin/activate’
             1> (nodejs_env) (base) will be showing on the left
 16) When done with work session:
       1- Type ‘deactivate_node’
       2- Close project

 

0

Please sign in to leave a comment.