How to host a next.js react project using IIS on Windows Server - javascript

We want to host the application on IIS server. We need it to support dynamic routing.
We tried downloading IIS node and we're not sure how to proceed.
Is there a file that needs to be loaded and needed to run, such as server.js?

You will need to install nodejs on the host system and have server running on a port, then use IIS as a reverse proxy on top.
This article goes into detailed steps on how to get there - https://alex.domenici.net/archive/deploying-a-node-js-application-on-windows-iis-using-a-reverse-proxy

Related

I want to deploy Node.js & React.js projects in same domain and server

As per my Title, I want to deploy Node.js & React.js projects in the same domain and server.
Basically, I want to host the application on cloudways server. https://www.cloudways.com/
I try to host there but due to the same domain action, it is not working as working in the local environment.
Front-end screenshot with package.json script structured(React.js): https://prnt.sc/xT4NAPxt0S99
Back-end screenshot(Node.js): https://prnt.sc/mSg_H4O6prF0
The given screenshot is from a local machine.
As you see here https://prnt.sc/xT4NAPxt0S99 we are using npm run build and after doing the build, we move that folder to the server folder and run npm i && nodemon index.js. It is working well in a single domain or IP in the local server well. But when I do the same process on a live server, it is not working.
Why I am using cloudways server?
For this, I don't need to install and set up MySQL, Node modules, PHP, and other things. Cloudways is doing all things when we create a cloud server.
npm i don't need to run this company on a server.

How to give the server port to client

I have a node server with several node projects. I use nginx to get them all responding on port 80. Now, this works for the initial http request. For the websockets, I need to use the direct server port. To keep everything alive while developing I would like to try this, projects will have a dev and live version. Once de dev is stable, I will copy it to the live folder. The live folder is runned by a systemctl script where I define a difrent port to the live version so I can dev without taking the live down. The problem I encounter now is, how can I get the running server port in my client side Javascript so that the dev page connect to the dev port and visa versa?
currently I'm only using express, socket.io and mysql. I have no further npm packages installed. I searched allot but there is not to mush I can find. I found how to connect the socket to the page url but I cannot use that because that URL will always be on port 80. Further I found allot of huge packages that has no use for me since the original page is just static, the dynamics all run over websockets.
Is there any way to parse the port number in the clients .js file like I could do fairly easy in php? And if so, what would be the most efficient way. I could let javascript check if the page uses the live or dev URL but I would prefer not to hardcode my dev URL into JS where it is for everyone to see.
run a third node.js socket.io server program, all your clients connect to this server first.
In this simple node.js program, determine the type of clients by any means. e.g. different user id for dev/production users
send the server url and port to your client according to its type (dev or production)
you may also use this technique to separate your users to different production servers.

SSL With node / IIS

My current setup with the company i've joined is IIS is being used as our main web server, using a CA signed certificate. I've got access to the certificate.pdx aswell as the private key.
I've setup a https node API server to handle some real time stuff / act as a simple additional middle layer, but my website is being served through IIS. The flow of the application is something like this.
1) Visit web page where IIS will then serve it
2) Click on a button, which then makes a GET request to my node server
IIS NODE
E.g 100.10.10.10:3000/mypage > Click Button > 100.10.10.10:4000/myGetRequest
At the minute i'm just using self signed in my development environment, and manually accepting the certificates.
My question is can I just use the same certificate that IIS is using on my node HTTPS server, or do I need a different one?
It would be best if the IIS could proxy the requests to your Node app. That way your Node app wouldn't even need a certificate (if it's on localhost). See this answer for more details:
Configuring HTTPS for Express and Nginx
It uses the example of nginx but you should be able to proxy the requests with IIS as well. See this tutorial:
Setup IIS with URL Rewrite as a reverse proxy for real world apps

How to run node.js in my web site server not my pc local server

Last 2 days I spent more time and read 50+ articles and video to understand node.js and after installation now I can see the result in browser by http//:localhost:3000/ But I have confused in many case that I describe below.
I do all of my work in my share hosting server where I my keep my web site: www.myweb.com
In every article about node.js, they are teaching how to get a result by below code in a browser by http//:localhost:3000/ in local pc server.
test.js
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');
But My Question:
If I use http//:www.myweb.com/test.js` in my browser, What will be the above code?
In case of local pc we write on npm node test.js, But In case of hosting server when any clint open the page like http//:www.myweb.com/test.js How to work it?
In case of php we used include ("head.php") to got something from that page But In this case How to make a call on node.js.
Well, what you need to do is understand how http web servers works.
Usually, on your remote machine (your server), you have an instance of a web server (ex : apache) running, which is listening to port 80 (standard port for http requests). It will handle every request made on that port, and manage routing to use the correct php/html file.
Then, it will run the php code server-side, to render an html file and serve it to the server. So the client will not see the php code at all.
Let's talk about Node.js. Node is an application that runs javascript code server-side, and can run an http server with using some modules. But the javascript code will never be shown to your client, he will only get the http response you send him (typically, the html page).
So now, with node.js, you need to do the same as the apache server did, by creating the http server. First, what you have to know is that not that many website host are offering node.js, or even console access. They usually serve the php/html files you put in the configured folder, and that's basically it. What you need is either a virtual machine, or a server on which you can install node.js and run it, or use a node.js hosting service, like heroku or nodejitsu to host your node.js http server.
So, to create the node.js http server, you need to create an http server (as you did in your code), and make it listen to port 80. Now, every http request send to your server will be handled by your node.js instance. Then, you can do anything you want with that request.
I hope I haven't been to messy.
You need to install NodeJS on the server. If this is shared hosting where you cannot install additional software then you will be unable to use NodeJS. In that case contact support of your web hosting company and inquire about NodeJS support.
On the other hand, if you do have root user or super user rights on a system, you can install NodeJS. For example for on CentOS/RHEL systems you can install using yum with the following commands.
sudo yum install epel-release
sudo yum install npm
For some of the other distributions of Linux: http://ask.xmodulo.com/install-node-js-linux.html
To access Node applications from your PC to the server, you also need to open a port in the server firewall that your Node aplication uses.

Why use NGINX with Meteor?

As far as I understand, Meteor is a full-stack web server, meaning you don't need another web server such as Apache or NGINX to makes it work. But from reading the guidelines on deploying Meteor, it seems like they use NGINX to serve Meteor.
Why is this?
Edit: Will there any impact if I just use the Meteor without NGINX or apache? Is it significant?
Meteor is not a web server. Especially, it cannot terminate SSL/TLS. That's why you might want nginx running in front of meteor.
Nginx placed in front of the Node.js build of your Meteor app tends to double the throughput of serving static assets (images, media files etc.) and reduce latency - see these benchmarks by #Stephan at Do I really need nginx with my Meteor/Node.JS app?
See also the recommended nginx configuration for Meteor.

Categories