burakorkmez / twitter-clone

MIT License
247 stars 47 forks source link

NODE_ENV is not recognized as an internal or external command. #2

Open LVSSandeepKumar opened 3 months ago

LVSSandeepKumar commented 3 months ago

When I added NODE_ENV in build and start commands in package.json as you suggested in the last module, "scripts": { "dev": "NODE_ENV=development nodemon backend/server.js", "start": "NODE_ENV=production node backend/server.js", "build": "npm install && npm install --prefix frontend && npm run build --prefix frontend" },

I faced this error...

` npm run start

twitter-clone@1.0.0 start NODE_ENV=production node backend/server.js

'NODE_ENV' is not recognized as an internal or external command, operable program or batch file.`

LVSSandeepKumar commented 3 months ago

SOLUTION :-

The error occurs because Windows doesn't support setting environment variables in the same way as Unix-based systems. To make this work cross-platform, you can use the cross-env package, which allows you to set environment variables across different operating systems in a consistent way.

Steps to Fix:

1. Install cross-env npm install cross-env

2.Update the start & dev script in your package.json: "scripts": { "start": "cross-env NODE_ENV=production node backend/server.js", "dev": "cross-env NODE_ENV=development nodemon backend/server.js" }

3. Try npm run start in your terminal npm run start

Sitholezw commented 1 month ago

ok the above solution works just make sure you update both Json.packages and by both I mean the internal and the external package