Create Node.js Website on remote server - javascript

I'm new to Node.js and I've been going through some tutorials. I've been able to make a simple web page in Node.js and run it as its own server from the command line on my desk top. However, I would like to create it to use it as a website that others can access, as well. Therefore I was wondering how can I host a web site built with Node.js on a remote server?

Option 1:
If you have public IP then you can host the website on your server
Option 2:
Find a service provider who can host your Node.js application. e.g heroku

I would recommend you check out Heroku. They offer a very simple hosting service at a variety of pricing tiers (including free) with a wide variety of add-ons. Deployment is as simple as pushing to a remote GitHub repository.

Related

Accessing JSON through Javascript- Different options

Still a newbie. I am building a simple quiz app which I plan to take make public. The questions will be stored in a JSON. Trying to understand the right approach to build this:
The javascript file cannot read the local json file through fetch (URL scheme file not supported) or using jquery (I get CORS error)
I want to expose only part of the json file and different question will be shared everyday.
Do I need a nodejs server to address these requests? What is the right way to host this on a server? When I buy a domain, do I need to keep a server running there to service these requests?
Would appreciate a response on the approach.
Thanks,
There are different "Components" in building and deploying an application on the web.
To handle the User Interface (Website as we know it), we would require HTML/CSS/Js or a frmaework like React, Vue, Angular etc.
This frontend will be connected to a server (backend) that can be developed by using Nodejs(Express), Python(Flask), Java(Spring), Go etc...
Then there is a database, you can use SQL or noSQL databases. (As per your requirements, I would recommend using MongoDb Atlas, a hosted cloud database)
Initially, you are going to develop Front-end and backend seperately as deifferent projects. Then Integrate the APIs.
Now, you can either host these projects seperately, or together.
Now, for testing servers, you can use Heroku or Netlify, these services host your projects for free (upto a certain limit), once you are done with development and testing. You can pay these services or choose other services to host your project and do other stuff like a good domain-name, a SSL certificate etc.

How to use a Node.js web server with an Apache Cordova Application

I have designed an Apache Cordova Application that uses a Node.js web server to pull data from a web API and allows the Javascript based project to use data pulled from this API.
Is there a way that I can use this Node web server across an iphone implementation of this cordova application? I am currently testing the application by pulling data from the website's API, hosting in on a node (ex. localhost:3000) and then pulling the data from that address in the JS file in my project.
How can I implement this server so that it can be used on an iOS mobile device?
If you want to host your Node server somewhere so that devices can see it on a network, then Amazon AWS Elastic Beanstalk has an easy solution for that - just upload your Node project in a Zip file and they manage the server environment for you.
There's several other options out there depending on your needs, for example Heroku may be a good alternative.

How to convert node.js application into cordova

we built a node.js application for desktop and tablet. It's completely web based application. Now I am planning to implement same application as native app in android using Apache cordova.
Under project directory, we have node_modules,public,.... all client side files are in public folder. When I invoke URL in browser, from client side I am making API call to check whether user already logged or not. like this we are making API calls to my server.
As per my understanding,native app is nothing but we are storing all the client side files into device. whenever user open app will load client side files and as per work flow it will make API calls.
Theoretically I understand that much.
where I stuck :
In desktop app , I used to make API calls with URL like /api/web/shared/reject/, here we don't need to mention server address like localhost:8080/api/web/shared/reject/ that everything browser will take care. This same thing how can I make it work in cordova applications.
How cordova will know whether it is localhost or something else...
Regarding this, I Goggled but I didn't find any tutorials.
can anyone suggest me the way.
Basically, is a concept problem.
Node.js is a technology specialised in backend and some of usages like extend some services/functions, etc.
When you talk of a localhost:8080 you are talking that your node.js implementation should be in a server (Amazon, Azure, your own server, nodejitsu, etc), and the public pages or the pages that the client should consume will be added into phonegap, specifically in your www directory and the references for localhost:8080 should be changed for your server (Amazon, your own server, nodejitsu, etc), and the files on your www directory could have references (via GET or POST to retrieve the data from the server. Remember, the Crossdomain problem doesn't happens on phonegap (maybe in a local enviroment should occur).
And Phonegap is a framework to develop front-end with HTML5, jquery, CSS3 and other releated technologies.
For your specific case the node_modules should be installed in the server too, not on the phonegap project.

How to actually deploy a node.js (or django) project on a hosted web server?

I know this question may seem stupid but I've been googling and asking this question for a while since I decided to start learning node.js. Ok so I have a hosted web server over at X10Hosting (https://www.x10hosting.com/) and I'm wondering how I could host a simple node.js web app on it. Thanks, any help is GLADLY appreciated (an actual tutorial or documentation would be really help).
You can't deploy a NodeJS/Django in this type of server.
When you sign up for a free hosting plan in x10hosting, they give you a folder in their server.
When a request come for you, Apache/nginx (which their are webserver) will execute the corresponding PHP file in your folder and will give to the client the output.
NodeJS is a very different type of installation.
It have is own process which it will bind a port, handle and process the request, and give the client the output. So, you will need to install it on their server, but i don't think x10hosting will do that just for you. And Django work the same way.
Nodejitsu ( https://www.nodejitsu.com/pricing/ ), the "owner" of NodeJS can host your app for free if the application is open-source.
I hope this will help you ;)
x10hosting's free hosting service is a shared hosting service, that means that you're allowed a folder inside a system shared by many users. That system has PHP5 and MySQL (as I read in their website), but Django and Node.js are a very different software stack. See, software stacks like Django or Node must be installed by the system administrator in order to serve content like a website. The administrator provided PHP5 and MySQL, but no Node or Python support. With a VPS, or Virtual Private Server, you are your own sysadmin, and free to install and configure whatever you want in your system, but it's not the case for shared hosting.
The Django Project website has a list, with some shared hosting or private hosting providers that support Django and some of them are free. For NodeJS you should checkout the Node Wiki's hosting list.
If you want to deploy easily you can use Heroku, it's free if you use only one Dyno (You don't need more if you create a website with low traffic)
Heroku and the really good documentation (with article for django and nodejs) : Documentation

How to efficiently develop client-side code for a web app without installing a local backend?

One of my team members is working only on client-side (Javascript) development for a web app with a large and complex backend.
I would like to avoid the need for him install and configure a local copy of the backend.
However, I wouldn't want him to need to push every small change to the dev server just so that he can test it.
We thought about getting the client to make the requests directly to the dev server, instead of to the same domain (the localhost) but this doesn't seem practical due to cross-domain request policies and authentication problems (cookies aren't getting sent).
What are some elegant solutions for developing clients without having a local backend?
Depending on how complicated your backend is, you might be able to create a mock backend using a lightweight web framework like Sinatra. I've had some success with this technique, but the services I've been mocking have been fairly simple. In some cases the mock backend mostly serves static JSON files.
I use Charles Proxy to map the URIs of the dev server's web services to localhost (where I run a light weight web server that serves up my static development code).

Categories

Resources