cross-env not populating NODE_ENV

I’m trying to use cross-env package to have two separate script configurations for production and for development.. but cross-env is not populating the values

config.js

const dotenv = require('dotenv');
const path = require('path');

// this is used for resolving the correct .env file
dotenv.config({
    path : path.resolve(__dirname, process.env.NODE_ENV + '.env')
});


module.exports = {
    NODE_ENV: process.env.NODE_ENV,
    HOST: process.env.HOST,
    LISTENPORT: process.env.LISTENPORT,
    DBHOST: process.env.DBHOST
  }

package.json

 "scripts": {
    "prod": "cross-env NODE_ENV=production&& node index.js",
    "dev": "cross-env NODE_ENV=development&& node index.js"
  }

index.js

const config = require('./config.js');

    expressApp.listen(config.LISTENPORT, () => {
      console.log(config);
    });

It doesn’t matter if I start the server with npm run dev or npm run prod, in either case the output to console from index.js is :

> cross-env NODE_ENV=development&& node index.js

{
  NODE_ENV: undefined,
  HOST: undefined,
  LISTENPORT: undefined,
  DBHOST: undefined
}

Not sure what I’m doing wrong.

Answer

I changed cross-env to export and it seems to work. Probably wouldn’t work on windows but at least works on linux/macos.

 "scripts": {
        "prod": "export NODE_ENV=production&& node index.js",
        "dev": "export NODE_ENV=development&& node index.js"
      }