0

I'm trying to upload my file to Heroku and need to include the PORT specification. All my other projects have had an index.js file whereas this is just html, js, and css so I"m using "live-server" and my script looks like this

  "scripts": {
       "devserver": "live-server"

},

but I want this

  "scripts": {
       "devserver": "live-server --port=process.env.PORT"

},

Any idea? Because I have to put npm run devserver in the Procfile but I need to make sure the whole thing accounts and implements the environment variable for Heroku.

ArrSky76
  • 33
  • 4
  • Does this answer your question? [Sending command line arguments to npm script](https://stackoverflow.com/questions/11580961/sending-command-line-arguments-to-npm-script) – Lewis Jul 16 '20 at 00:42

1 Answers1

0

You can't make something in package.json dynamic. You can, however exec commands in Node. So, you are better off changing your package.json script to execute a special file:

{
    "scripts": {
        "devserver": "node startserver.js"
    }
}

Then exec your actual function, like this:

const { exec } = require('child_process');

exec('live-server --port=' + process.env.PORT, (error, stdout, stderr) => {
    if (error) {
        return console.log(`error: ${error.message}`);
    }

    if (stderr) {
        return console.log(`stderr: ${stderr}`);
    }

    // console.log(`stdout: ${stdout}`);
});
NeoNexus DeMortis
  • 1,286
  • 10
  • 26