Friday, 1 December 2023

Nodejs virtual environemnt

 

1. Use npm and Local node_modules

By default, Node.js projects are isolated at the project level through their node_modules directory. When you run npm install in a project, all dependencies are installed locally in the project's node_modules folder.

Steps:

  1. Create a new project directory:

bash

mkdir my-nodejs-project

cd my-nodejs-project

 

  1. Initialize a new package.json file:

bash

npm init -y

  1. Install dependencies:

bash

npm install kafka-node google-protobuf

  1. All dependencies will be stored locally in the node_modules folder, and your package.json will track them. This isolates the project environment.
  2. To run your script:

bash

This is equivalent to creating a Python virtual environment, as dependencies will only affect the current project.

No comments:

Post a Comment