How to Fix the “NODE_ENV is not recognized” Error in Node JS Last Updated : 24 Jul, 2024 Comments Improve Suggest changes Like Article Like Report We generally come across the error message "NODE_ENV is not recognized as an internal or external command, operable command, or batch file" while trying to set an environment variable in a package.json script in Node JS. This guide will assist you in resolving the issue with a straightforward solution.When using the following syntax in a Windows environment, it won’t work as expected:"scripts": { "test": "NODE_ENV=test mocha",},This leads to the error message:“NODE_ENV” is not recognized as an internal or external command, operable command or batch file.Example: Below is the code example which generate error. JavaScript //app.js const express = require('express'); const app = express(); const port = 3000; // set session in the / route app.get('/', (req, res) => { // session variable res.send(`<h1>Hey Geek!</h1>`); }); app.listen(port, () => { console.log(`Server is running on http://localhost:${port}`); }); JavaScript //package.json "scripts": { "start": "NODE_ENV= node app.js" } Output: To overcome this issue, this is how you set an environment variable in windows:"scripts": { "test": "SET NODE_ENV=test & mocha ",},After making this adjustment, the “NODE_ENV” error should no longer occur, and your script will execute without any issues.Example: Below is the code example which generate error. JavaScript //app.js const express = require('express'); const app = express(); const port = 3000; // set session in the / route app.get('/', (req, res) => { // session variable res.send(`<h1>Hey Geek!</h1>`); }); app.listen(port, () => { console.log(`Server is running on http://localhost:${port}`); }); JavaScript //package.json "scripts": { "start": "cross-env NODE_ENV=production node app.js" } Output: Comment More infoAdvertise with us Next Article How to Fix the “NODE_ENV is not recognized” Error in Node JS A ashishbhardwaj18 Follow Improve Article Tags : Web Technologies Node.js Express.js Similar Reads How to Resolve npm Command Not Found Error in Node.js Node Package Manager (npm) is the default package manager for NodeJS. It allows developers to easily manage libraries and dependencies in their NodeJS projects. It is an essential tool for managing the installation and versioning of packages from the npm registry.The npm: command not found error hap 4 min read How to Fix the "partial is not defined" Error in EJS ? Encountering an error message like "partial is not defined" can be a stumbling block when you're working with EJS (Embedded JavaScript) templates. This error typically pops up when you're trying to use the `partial` function in EJS, but it's not being recognized. Don't worry, though it's a common hi 3 min read How to resolve 'node' is not recognized as an internal or external command error after installing Node.js ? Encountering the error message ânodeâ is not recognized as an internal or external command after installing Node.js can be frustrating, especially when youâre eager to start working on your project. This error usually means that your system cannot find the Node.js executable because the path to it i 2 min read How to resolve a "Cannot find module" error using Node.js? This article outlines the steps you can take to troubleshoot and fix "Cannot find module" errors in your Node.js projects. These errors typically arise when Node.js cannot locate a module you're trying to use in your code. Table of Content Error "Cannot find module" Approach to Solve the ErrorInstal 3 min read How to Define the Required Node.js Version in package.json? Like the other project dependencies we can also define the node js version for a project. As we know that node is javascript runtime so it will not be contained by the normal dependencies. It ensures that the project should run and install only the compaitible node and npm version.ApproachThe define 3 min read Like