How to run the node app in different port - as temporarily?

28,106

Do like this If you want to access PORT variable from process.env you have to use this command to access.

PORT=8081 node server.js

. You are using wrong syntax

Share:
28,106
user2024080
Author by

user2024080

Updated on July 29, 2022

Comments

  • user2024080
    user2024080 over 1 year

    In my app, I have the configuration like this:

     module.exports = {
         'port': process.env.PORT || 8080,
         'database': 'mongodb://xxx:[email protected]:13456/practical',
         'secret': 'ilovescotchscotchyscotchscotch'
     };
    

    but at present, I would like to run my app in different PORT number say, 8081 or something else. because I need to run 2 different apps which is configured as same way.

    what is the correct way? - any one help me?

    Thanks in advance.

    I tried this answer already : How to change value of process.env.PORT in node.js?

    But I am getting this error: ( I am using windows shell )

    C:\Tutorials\try\NodePractical\MEAN-Family> env:PORT = 1234 server.js
    env:PORT : The term 'env:PORT' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1
    + env:PORT = 1234 server.js
    + ~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (env:PORT:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException