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
in order to create simple http server with nodejs + Express:
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:
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:
For connecting in Dart, I would recommend making use of
Uri.parse
instead ofUri.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:
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.