skip to Main Content

I have a server that is running Windows 10. I created an Express project using this repo. I ran in development mode just fine and I now want to deploy to production. I followed the instructions to do so:

  • Check for linting errors: npm run lint
  • Build the project for production: npm run build
  • Run the production build: npm start

However, when I try to send a GET request to the IP address of the server, I get a connection timed out error. Was I supposed to do other things to prepare for deploying to production? Do I need to specify a port number? I’m relatively new to web server development, so I apologize if this is a dumb question. I am sending the request through a Flutter app:

  void test() async {    
    var url = Uri.http('ServerIPAddress');

    try {
      var response = await http.get(url);
      if (kDebugMode) {
        print('Response status: ${response.statusCode}');
      }
    } catch (e) {
      if (kDebugMode) {
        print('ERROR: $e');
      }
    }
  }

Note: this is all on an internal network. It is not exposed to the public internet.

2

Answers


  1. in order to create simple http server with nodejs + Express:

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

    Then you can run in your browser like: http://localhost:3000/

    For running in a server, please search how to allow port in firewall. For CentOS:

    firewall-cmd --zone=public --add-port=3000/tcp --permanent
    firewall-cmd --reload
    
    Login or Signup to reply.
  2. The express-generator-typescript generates three different environment files by default which each defines some options for running in the different modes. You can find the different default profiles here:
    https://github.com/seanpmaxwell/express-generator-typescript/tree/master/lib/project-files/env

    For port number, these are the ones it will use by default:

    • 3000 (development)
    • 8081 (production)
    • 4000 (test)

    For connecting in Dart, I would recommend making use of Uri.parse instead of Uri.http because it does make it a lot easier since the latter is a bit more complicated to use.

    So something like the following for connecting to a production running server if using the default profiles:

    var url = Uri.parse('http://<IP_OR_DOMAIN_TO_SERVER>:8081/');
    

    Should be noted that in "real" production, you would not have this instance public but might instead have it forwarded though a proxy which can have HTTPS and run on port 443. E.g using nginx.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search