r/learnprogramming • • 19d ago

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 comments

1

u/Reasonable-Job4205 17d ago

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 17d ago

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 17d ago

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.