Node.js/Express.js App Only Works on Port 3000

后端 未结 16 2187
暖寄归人
暖寄归人 2020-12-12 13:23

I have a Node.js/Express.js app running on my server that only works on port 3000 and I\'m trying to figure out why. Here\'s what I\'ve found:

  • Without specifyi
相关标签:
16条回答
  • 2020-12-12 14:09

    If you want to show something you're connected on 3000

    var express = require('express')
    var app = express()
    
    app.get('/', function (req, res) {
      res.send('Hello World!')
    })
    
    app.listen(3000, function () {
      console.log('Example app listening on port 3000!')
    })
    

    I hope that will be helpful to you

    0 讨论(0)
  • 2020-12-12 14:09

    If you are using Nodemon my guess is the PORT 3000 is set in the nodemonConfig. Check if that is the case.

    0 讨论(0)
  • 2020-12-12 14:10

    In bin/www, there is a line:

    var port = normalizePort(process.env.PORT || '3000');
    

    Try to modify it.

    0 讨论(0)
  • 2020-12-12 14:11

    Make sure you are running from that folder of your application, where you have the package.json.

    0 讨论(0)
提交回复
热议问题