Search code examples
javascriptnode.jsnpmyarnpkgdotenv

dotenv: command not found in nestjs project


I am working on a NestJS project. I am trying to start project but I am getting error: dotenv: command not found in the terminal. I have checked the packages.json and I can see to dotenv installed. Moreover I have tried to install dotenv with Yarn but still I am getting same error.

Dependencies in package.json:

"dependencies": {
    "@nestjs/common": "^8.1.1",
    "@nestjs/config": "1.0.2",
    "@nestjs/core": "^8.1.1",
    "@nestjs/jwt": "^8.0.0",
    "@nestjs/passport": "^8.0.1",
    "@nestjs/platform-express": "^8.1.1",
    "@nestjs/swagger": "^5.1.2",
    "@prisma/client": "3.3.0",
    "bcrypt": "^5.0.1",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
->  "dotenv": "^10.0.0",
    "express-rate-limit": "^5.5.0",
    "helmet": "^4.6.0",
    "nanoid": "^3.1.30",
    "nodemailer": "^6.7.0",
    "passport": "^0.5.0",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.12",
    "request-ip": "^2.1.3",
    "rimraf": "^3.0.2",
    "rxjs": "^7.4.0",
    "swagger-ui-express": "^4.1.4"

},

The starting script that I am using:

"start:dev": "dotenv -e env/local.env -- nest start --watch",

Solution

  • I found the solution and it may help someone else. To run dotenv command in terminal we need dotenv-cli. Installing dotenv-cli with

    yarn add dotenv-cli
    

    or

    npm install -g dotenv-cli
    

    solved my problem.