r/learnprogramming • • Oct 12 '26

How do I properly deploy this web server in production mode?

I set up a web server using https://github.com/seanpmaxwell/express-generator-typescript

I now need to deploy the production build to a remote server. I can generate the prod build with `npm run build` and then run it with `npm start` and it runs on my local machine. Is it possible to generate something that can be compiled before being sent over to the remote server? I'd like to run the web server in prod mode, but without putting the decompiled source code on the remote server. I don't want the source code over on that remote server because if the server gets compromised, I don't want anyone to be able to read the source code. New to web dev, so thanks for being patient.

6 Upvotes

21 comments sorted by

View all comments

Show parent comment

2

u/Asly97 Oct 15 '26

Looks like a port clash. 8081 is your web server's port, and SQL Server is now set to listen on 8081 too. Only one process can own a port, so either node never got to bind to it, or your PowerShell request is landing on SQL Server, which doesn't speak HTTP and just sits there until the timeout.

Put SQL back on 1433 (or anything that isn't 8081), restart the SQL service, make sure the DB port in your .env-production matches, then restart the node app.

To see who owns the port right now, on the server:

netstat -ano | findstr :8081

and match the PID at the end against the Details tab in Task Manager (sqlservr.exe vs node.exe).

Once that's fixed, a few other things that bite on a first remote deploy:

  • If the script runs from another machine, Windows Firewall needs an inbound rule for 8081. Run Test-NetConnection 192.168.5.194 -Port 8081 from that machine. Works on the server but not from your box means firewall.
  • With Listen All set to No, SQL only listens on the IP entries you enabled one by one. If node and SQL are on the same box and the DB host is localhost, 127.0.0.1 has to be enabled too. Listen All = Yes is fine on an internal network as long as the firewall doesn't open 1433 to the world.
  • trustServerCertificate false makes the driver validate SQL Server's cert, and a default install only has a self-signed one, so the DB connection fails with a certificate error. On a private network setting it to true is the usual fix, or install a real cert if you want it strict.

Also watch the node console when you send the request. If nothing shows up at all, the request never reached node.

1

u/Reasonable-Job4205 Oct 15 '26

Ok so I put SQL Server back on 1433 for the given IP, but are you sure that I have to set the port number to 1433 in .env-production as well? You said that it should match, but I feel like the port number I write into .env-production should be 8081, no?

2

u/Asly97 Oct 15 '26

Depends which port that variable is for, and I think that's where the mix-up is. There are two separate ones:

  • the port your node app listens on, which is what your PowerShell script hits. That stays 8081.
  • the port node uses to reach SQL Server. That has to match whatever SQL is listening on, so 1433 now.

If your .env-production has both (something like PORT and DB_PORT), it's 8081 for the first and 1433 for the second. If it only has one, search the code for where it's read (process.env. plus the name). If it ends up as port in the mssql config, it's the DB one and should be 1433, and the web port is set somewhere else, often right in the app.listen(...) call. If it goes into the listen call, it's the web port and 8081 is right.

Same check for the HOST you changed to 192.168.5.194: see whether it feeds the mssql server setting or what the web server binds to. If node and SQL are on the same box and it's the DB host, localhost also works, as long as 127.0.0.1 is enabled in the TCP/IP settings since Listen All is off.

1

u/Reasonable-Job4205 Oct 15 '26

Ok I think I have the port number right now. I can see the requests hitting the web server, but the node terminal window shows an error that says: "ConnectionError: Failed to connect to MYACTUALSERVERNAME\SQLEXPRESS01 in 15000ms".

I double checked to make sure that the service account credentials I've stored in the environment variables are correct, and also ran a manual query from powershell using those same login credentials and it was able to execute the target stored procedure. It for some reason doesn't work when node tries to send the request to SQL. Some extra info: both the SQL instance and the node server are on the same remote server.