How does hosting a website work when using a Backend/Database? - node.js

I have hosted static sites before and here;s how it worked:
I have my HTML, CSS, JavaScript files ready
I upload them to a hosting site
and the website goes up
But now I'm starting to work on backend development with Nodejs and using Mongodb for databases.
I'm currently running my Mongodb database on a localhost.
Do I follow the same procedure as before when trying to host the site, or is there something I have to do differently?
(I figured It's different, but I don't know how to approach it)

Related

Hosting Nodejs Mongodb website with frontend but not React

I'm very new in MERN stack development, I made a blog website with backend used HTML CSS JS NODEJS & MONGODB. and I want to host in netlify and heroku.
Tried So many times but got error.
My Github repo link :
here
Can any one completely explain how to host ?
If you're just getting started with hosting your apps, try a newer generation app hosting platform where you just connect your GitHub repo and it does everything else for you.
Node.js and Mongo is perfect for Adaptable.io. The free tier includes a Mongo database. Here's the guide to deploying a Node.js App with MongoDB. You could also try Render but they don't have MongoDB.

How do I properly upload a localhost website online?

I have a ReactJS project for my Front and a NodeJS project/server using Express for my back. My Front depends on my Back because for example in the Login part, I ask the server if the user is already in our database.
To execute my project, I just open 2 terminals and do npm start in each Front and Back.
I know that in order to upload a website with a personal domain name, I should:
Buy a domain name
Pay a subscription to a web-hosting website like GoDaddy, Bluehost, Hostgator etc.
If I pay a subscription to some web-hosting website, will I be able to put my Front AND Back? I have seen some tutorials online and people just make a simple HTML/CSS/JS website and upload it. I never see anyone uploading their own Server and making requests to it.
I'm not asking to merge both my Front and Back. I want to know how do people upload online their React front and Node Server online, for them to be always executed and talking to each other. I just can't see the relationship and explanation on how uploading both.
Your react frontend doesn't really need a server, you'd need to build a release bundle and that can be served from any static filehoster. For your backend though you need a node.js hoster like AWS or heroku, follow their tutorials to upload your project.
You could also then serve both from the same hoster and read into connecting frontend and backend like mentioned by #FedeSc
An easy solution for your use case could be digitalocean or any similar site that offers a whole virtual system to operate with. You can then ssh into the server as it was your computer and use the terminal there. It is cheaper than Heroku if you wish to make your site available without 30 seconds waiting time (that is what Heroku does in a serverless fashion if you are on a free plan). There are dozens of sites like this but I had good experience with digitalocean and a basic plan is $5/mo.

How to publish and host MEAN stack project in GitHub

How to host AngularJS, MonogDB, Node.js, ExpressJS project on GitHub?
I have uploaded normally like a static HTML page but it didn't work.
How to host this project as it consists of four technologies
You can't host a MEAN stack site on GitHub Pages:
GitHub Pages is a static site hosting service and doesn't support server-side code such as, PHP, Ruby, or Python.
Similarly, GitHub Pages doesn't support Node.js or MongoDB.
Since github pages host only static resources like html, css and javascript you cannot host a node application there. You could try hosting your project on Digital Ocean, Heroku, AWS etc. These provides free trials versions as well. Here you can set up your own server and get things working.

How to host HTML node.js application

i have developed a simple webapp using socket.io and node.js and was wondering how i would deploy it to a server? My application uses an HTML file with a canvas element the user interacts with how would i deploy this, the css and the js files and the app.js file to the server?
thanks
In some hosting companies that support Node.js (like Nodejitsu and Heroku) you can deploy your static files as part of your application code. In other words, when you deploy your app both your code and static files (JS/CSS/Images) will be deployed.
The downside with this approach is that you cannot easily just change a CSS file like you can in a more traditional deployment where you can just FTP a new CSS file to the production server. You could bypass this if you host your CSS files somewhere else, though.
I don't have experience with AppFog but I suspect the same is true.
You have a 90 day free trial at Azure. Believe it or not but they have great support for node.js. Read more at http://www.windowsazure.com/en-us/develop/nodejs/

How to replace IIS with Node.js for simple websites

I am coming from Microsoft world so please bear with me on this. I was told I could install node.js and use that as a web server instead of IIS. This is a very small business application. In IIS I can create virtual directory and point to the location of the web page and everything works just fine. Based on very little I read, I have few questions;
Is it possible to run node js as a windows service or any other form so that it runs for ever? I did find the forever package that I think I can use.
In IIS, I can create virtual directory set the port and thats it, I have myself a website.
I do not see any examples where I can use a directory where I have a web page, written in java script and point it to run as a web site. All the examples have some thing like server.js and that runs and routes the call. what is the other way to host web sites and use node.js to simple run as a fast web server.
I was told I could install node.js and use that as a web server instead of IIS.
This is true, but as you already found out then you are in charge of providing for things that IIS was already doing for you (e.g. automatically restart on reboot, or on crashes, hosting multiple sites by creating virtual folders, et cetera.)
You can indeed get all of these things worked out in Node.js and there are several libraries that help on each of these areas. It's not too hard but you'll need to do a bit of researching.
You can also run Node.js behind IIS. Take a look at iisnode http://tomasz.janczuk.org/2011/08/hosting-nodejs-applications-in-iis-on.html
Is it possible to run node js as a windows service or any other form so
that it runs for ever?
The library Forever takes care of restarting the site when it crashes...but I don't know if you can run it as a Windows Service. I haven't tried that.
In IIS, I can create virtual directory set the port and thats it,
I have myself a website.
I assume you are talking about a site that serves static HTML files, right? If that's the case that's very easy to support in Node.js either writing your own web server or using Express.js to serve static files.
I do not see any examples where I can use a directory where I have a web page,
written in java script and point it to run as a web site. All the examples
have some thing like server.js and that runs and routes the call.
Here is an extremely simple example to serve plain HTML files in Node.js https://gist.github.com/2573391 Don't use this in production, though. It's just an example and it does not have any kind of error handling or security.
what is the other way to host web sites and use node.js to simple run
as a fast web server.
As others have said, you should look into Express.js http://expressjs.com/ It provides some of the infrastructure that you are very likely going to need when building traditional web sites.
You say you're running a "very small business application" behind IIS. Unless it's written for Node.js (in JavaScript), it won't work.
There are no examples pointing to a directory and running that as a website, because that's not how things are done in Node.js. You write a Node.js-application and pull in a webserver-library.
Put simply, In Node.js, you don't embed the appliation in the webserver; you embed the webserver in the application.
When I used node.js, I redirected HTTP requests by a proxy server, nginx. I don’t know if you can directly bind node.js as an HTTP server, but for what’s it worth, nginx is pretty nice!
First things first, allow me to share an introduction. IMHO you should take this decision ( of moving from IIS to nodeJS) by adding various parameters. I belong to the Java & PHP community yet I use NodeJS to achieve extremely specific implementation where NodeJS perform the fastest ( fast IO, AJAX-JSON responses & more ). As you are coming with a Microsoft background you should bare with less comfortable solutions.
Yes, its possible to run NodeJs as a windows service and Forever will do fine.
and yes you can create "Virtual Directories" but by creating symbolic links to each of your customer's web site.
I recommend to take a good look at bouncy & express, If you're willing to take this step then these packages is just what you need.
Cheers!

Resources