I've made a node.js application which hosts a webserver over http using the express framework but i'd like to upgrade to https.
However I can't seem to find a good way to do this since the application will be run on different PCs which could have different public IP addresses so pre-generating a certificate wouldn't be possible.
Furthermore if possible I'd like to keep the application as portable as possible so locally installing open-ssl or expecting it is locally installed isn't really an option unless it can be packaged with the server itself somehow.
How would one go about building what I've described above?
If anyone could give me some pointers that would be fantastic.
Use docker/kubernetes together with a reverse proxy that automatically generates SSL certificates. I can recommend Traefik.
Related
I am confused as to why when building a node/express application I dont need to use another web server but when working with Java or Spring or a python backend usually a webserver like nginx or apache is used. I am getting confused as to what Apache and nginx do, don't they just handle HTTP requests just like we do in node or express? But then in Spring there are controllers that handle the requests so why do we need to have JBoss or Apache running?
In the old times there was a strict separation between the "application" and the "application server"/"web server". Application servers (like JBoss) provided the configuration of the resources (connections to DB for example), etc. to the application deployed on them. Web servers (like Apache) provided the configuration for possibly multiple web applications hosted on them.
Currently, in the era of self-hosted apps (which means: apps that contains embedded HTTP server) you often don't need a separate webserver. But tools like Nginx are still used for example as load-balancers, etc. Application servers (JBoss, etc.) are not often used nowadays, because of the embedded HTTP servers that you're able to configure without asking Ops-people to do it for you - it's quicker and more convenient.
If you are writing a NodeJS application then you don't "need" another server, except maybe when you are scaling a production ready deployment
The simple answer is that express, Apache, nginx and JBoss are all web server. Since all of these are web servers they each can pretty much do the work of each other. However, each of them have strengths and weaknesses which is why often times they can work together. For example a common practice is to place an express server behind nginx to let nginx handle load balancing, static assets and SSL termination which nginx is very good at but maybe let API and websocket connections fall through to the express server which is what express is typically good at.
A developer may pick Apache if they are working with PHP because the integration is so good but pick JBoss if they are working with Java EE.
I'm currently learning NodeJS and pretty excited about it.
But here is one thing that I am unsure and need help about.
As we know that NodeJS has its own internal http web server and we can simply create using http.createServer() method.
My questions are:
Is the internal http web server that NodeJS has, meant to replace similar http web server like Apache or Nginx?
If I need to create enterprise-scale application, does NodeJS internal web service capable of doing this? Or do I need to still use Apache/Nginx?
Please help. Thank you.
Adrian
node.js does not require a web server the likes of Apache or nginx, it is its own web server.
Walmart has used node for, in their words, "end-to-end javascript"... that is certainly enterprise-scale, though they don't explicitly say they're relying on http.createServer, end-to-end javascript would eliminate Apache or nginx and I doubt they've developed some exotic solution (though socket.io is a possibility)... generally speaking if you're using node on the web, you're using the built in web server in at least some capacity.
There perhaps is some benefit to using nginx as a reverse-proxy/static file server on the front end. If I were designing my "perfect system" I'd probably do that, but I'd still be passing back requests to the built in web server in node.
You don't need to use Apache or Nginx with node.js, but in practice, its probably a good idea.
Basically, Apache would sit in front of your node.js, and relay requests to and from your node app, using something like mod_rewrite.
The node http server module is great for firing up quick applications, but if you need things like SSL, complex mod_rewrites, directory security, detailed logs etc (ie all the stuff you would need in a commercial application), you need (or at least, its easier) to use Apache or Nginx in front of node.
Ok so finally decided I was way behind in knowing some of the frameworks/platforms that are out like Angularjs, NodeJS, Knockout, Backbone etc etc. And so decided to learn NodeJS first, and have set it up on a local vm of ubuntu server.
So was wondering if NodeJS was supposed to be paired with another server software like apache,nginx, etc. And let apache/nginx just serve up the basic pages and then just let node do the data communications since their site says its "for easily building fast, scalable network applications".
Because I have seen several questions on S.O. asking how to get NodeJS to run on port 80, which implies they want to run node as a regular server or they just dont want to have to always specify a port when doing requests. And have not seen anyone comment or say that node was not meant to be used like a regular server. So was hoping to get to an answer on this.
Node.js can be used standalone, out there are good frameworks to do it like express. You can clusterize your process in the same physical machine (and the same port) really easy via its native module cluster. Also, I'm sure you can use Node.js like a reverse proxy too, but some developers prefer using other tools to do it (in my enterprise, we use Nginx with some of our node.js apps).
So, in short: You dont need Nginx or Apache at all, but you can use if you want. It's very cosy to some people use Nginx to do the load balance, or even other stuff like handle the https or server static content. It's your choice at the end.
You should play something with the native library http or https first, and then check express or another framework. You will see wich parts of Node.js you love and which do you dont feel awesome.
I've acquired a hostgator vps level 1 account to use with node.js development. But when it comes to servers I'm a bit of a noob so I was wondering if the more experienced developer could give me suggestion of to setup my new account to work best with node.js. What would you recommend me to install. Apache? Python? Php? and so on?
Would you recommend me to use Haraka as an email server?
I'm planning to use this server for websites and services with node.js as the backend.
Any suggestions would be appreciated and could possible be good for other getting the same type of account. =)
PHP and Python have no relation to Node.js/Javascript. Remember that, unlike PHP apps which rely on a third party web server (i.e. Apache/Nginx/IIS), Node.js apps act as their own web server. If you don't need Apache, don't install it. It takes up resources and will most likely be listening on port 80 (preventing your node app from doing so).
Node requires only a very minimal environment. You should install Node.js, and probably a C++ compiler. Other than that, it simply depends on what you need for your particular app.
There are lots of resources for how to get started with node. For example: https://stackoverflow.com/a/5511507/2210128
Are there any examples or conventions out there of how to use node.js to host multiple web apps?
I'm already aware that node itself can be used to build a server, but I'm curious as to whether there have been implementations where you aren't necessarily running it all the time. Strictly for the reason that perhaps there are multiple sites being hosted, each with their own copy of a framework, static files and custom functionality.
Or maybe you do run one instance of node and code a multiple site architecture to ensure one bad site doesn't take the server downin some way?
Virtual hosts, ensuring that one site can't crash others...these are all things that have been considered with other platforms, but I have had some difficulties finding for node! :)
I am already aware of connect, express and other middleware, however it doesn't cover what I'm asking here.
If you're worried about runtime isolation, each "site" should run it's own node process. Then use a proxy like node-http-proxy that will do host header based routing. Another great node based option is bouncy, but you don't necessarily need to use node to do the host based routing. You could just as well use haproxy, nginx, etc.
The baseline RAM overhead of each node process is very small (~10mb - 15mb). Also, if you do HTTP based routing you can spread your sites easily across machines, user home directories, etc.
If you want to handle the site/host registration programmatically, I would use seaport and then communicate the hostname and host + port details back to the proxy so that the routing table can by dynamic. This would also make it fairly easy to scale a site across multiple node processes.
Good luck!