I am learning Node.js and this is my first code.
I created a file called server.js below with the code
server.js
const express = require('express');
const dotenv = require('dotenv');
//load env vars
dotenv.config({ path: './config/config.env'});
const app = express();
const PORT = process.env.PORT || 5000;
app.listen(
PORT,
console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`)
);
I have this section in my package.json file
package.json
"scripts": {
"start": "NODE_ENV=production node server",
"dev": "nodemon server"
},
Here is the content of my config.env file config.env
NODE_ENV=development
PORT=5000
When I run npm run dev
everything is fine and runs
When I run npm start
to run production, I get the error below.
'NODE_ENV' is not recognized as an internal or external command, operable program or batch file.
How can I resolve this? I need npm start
to run