I'm intending to host an online portfolio and I have several node.js projects I'd like to host.
So I'd like to host one project on domain.net/project1 and the other on domain.net/project2
Do I need to use a single nodejs process to do this, or is it possible to have each of my separate nodejs projects running independently?
Is it possible to assign a nodejs process to each subdomain?
A better approach will be to host your NodeJS projects independently and then use the domain(hosted and provided by platform) to Custom Sub-Domain(created by you) pointing to point each of your projects to custom subdomains like project1.mydomain.com. This will provide you the flexibility to deploy your node applications on Heroku, AWS or any other hosting environment.
Thus you get freedom of choosing your own hosting platform and can have as many projects hosted as needed. I have attached an architecture diagram for the same and the link to the original draw.io document. Also please note that this is just a sample, and your design may vary as per your specific requirements
You can refer this Arc diagram for more details.
You can use nginx or apache http for host each project or create a path that contains sub paths for each one.
Here come references:
Apache http
nginx hosting
Related
I am working on a learning project. I have build an authentication system in nodejs using local and Google strategy. Front end is a react app. There are two options for hosting
Deploy front end on static hosting providers like netlify or github pages and backend node app to heroku.
Deploy both backend and front end on heroku with front end code in the public folder and use express.static('public')
I am confused about both these approaches and could not find the answer on the internet. It will be a lot of help if you can explain the pros and cons of both the method and which one is suitable in what conditions. Links to the articles are also appreciated. Thank you in advance.
First approach
Pros:
Static content served from a different server has more optimization potential (using S3/CloudFront edge caching), nginx is blazingly fast for serving static files
Less network traffic on one server (content can be served from multiple points in parallel)
The nodejs application doesn't have to "waste" time serving static files that never change as has more time for actual dynamic content
Cons
Needs more configuration, since it's running on a different origin (dealing with CORS, appropriate security settings)
Premature optimization
More maintenance
Second approach
Pros:
Easier to deploy
Fast enough in most cases
I can give you an example based on the company I work for. We separate back and front on different servers for security and convenience. We block all ip's from making requests to our backend and only release the ip of the front server. We create specific rules for each server separately and if one of the servers stops for any reason, it does not affect the other one.
But this decision depends a lot on the type of application you develop and also the structure you need for your project. But consider the following: security, maintainability, and convenience.
I want to create a modular node.js application stack containing a set of applications. The idea is that app1, app2, etc can use the controllers and models.
Inside each app folder, I can have app specific package.json, app.js, etc.
I am using express.
I have two issues:
Is it possible to have that structure?
Why I'm not able to deploy such an app set on GCP? When I try It throws 500 internal server error.
enter image description here
To create a similar architecture, even if I didn't find a way to have the same, you should use services. According to the official GAE doc:
Use services in App Engine to factor your large apps into logical
components that can securely share App Engine features and communicate
with one another. Generally, your App Engine services behave like
microservices. Therefore, you can run your whole app in a single
service or you can design and deploy multiple services to run as a set
of microservices.
Does this work for your use case?
Regarding question 2, you didn't provide any information about your current process, so I cannot help you. Please edit the question adding the deployment configuration (app.yaml, etc.) and how is it performed. Please delete any sensitive information before posting it.
I want to purchase shared hosting with node js support. Can you provide us company name which support nodejs on shared server.
Thanks in advance.
You have many options out there. It depends on what you want to do but I would go for:
Heroku: It has a free option and it's compatible with integration testing tools like Travis. You can easily configure databases and also create environment variables easily
Glitch: It's also for free and you can just start programming because the server is already configured. I usually use this service when I want to try some small projects on node.js and I need a server to share what I'm doing.
What is the most scalable and simple way to have a node app serving many domains ?
I feel like many hosting services like nodejitsu don't support this (they actually told me this in an email)
My idea is to have the users redirect a domain to me (like tumblr) and then on the nodejs app I get the domain I'm serving like this:
req.headers.host
and then I simply serve the "template" with the user's options in the DB..
Essentially, you're describing a reverse proxy, no? And if so, why reinvent the wheel? Nginx will not only provide the reverse proxy functionality, but as your project grows you can leverage it for load balancing between a cluster of node apps. Even if you only have a couple of hosts, when you need to scale your architecture, decoupling each host is the first place you will start. Might as well get ahead of it from the get-go.
As for service providers like Nodejitsu, they use the singularity of a hostname as a means to monetize their service. They don't want you hosting a hosting platform on their own hosting platform =)
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!