How to deploy a program with a separate server and client code? - javascript

I recognize this question is ridiculously stupid but I need an answer to this. I have tried going through google for an answer to this, but no luck so far.
So, I am going to build an application in JavaScript (using React and Redux) with separate client and server logic. The code for each will be housed in separate files. If I deploy both my server and client code logic to heroku, how will it be deployed by heroku?
By my understanding, heroku deploys a single app, and it will see this as essentially two different apps. Do I need to write both client and server logic together and push them up to Heroku necessarily?

Without an example of what you are trying to do with your app it is quite hard to give a correct answer.
But if you want to use Heroku node.js you will be deploying both server and client logic in one project.
Here is an example for react.js: http://ditrospecta.com/javascript/react/es6/webpack/heroku/2015/08/08/deploying-react-webpack-heroku.html

Related

should I use a CDN like cloud flare for heroku backend?

I'm creating a website using netlify (static html, css, javascript) as my front end and heroku (node.js) as my backend
since netlify itself has CDN I don't think there's any necessity to use cloud flare
However, as far as I know the Heroku backend runs only on one server at one place
so if I use a CDN like cloud flare for heroku will it make multiple "copies" of my server and distribute them? or am I understanding the concept incorrectly?
I'm a bit new to all this sorry in advance if I don't make sense

Can web chatting application using socket.io be built without ssh access or keeping the terminal running?

I have a website written in php. Till now I used setTimeout with ajax to update chats simultaneously but after that didn't work I learnt about socket.io. I need to implement private messaging and I have got some things covered in socket.io but when I ran it on localhost I had to keep the terminal open as long as I wanted to chat.
1. How am I supposed to do that on my server which is Hostinger currently. Is there some terminal I need to run or do I need ssh(shell) access which I don't have at the moment?
2. If there isn't, how would the node script keep running?
3. And since socket uses node, how would the app use node modules? Do they need to be uploaded to the hosting space?
Apart from that, if there is any private messaging and group messaging implementation anyone knows about even other than how it could be done in socket.io it will be very helpful if you could suggest. I need the users to chat among themselves not with me.
Thanks in advance!
You can do this by using node js ,socket.IO and express.js
Link given below can provide you with a rich documentation to reach a solution.
https://socket.io/get-started/chat
For running your application in background you can use PM2 process manager.
For documentation refer below link
http://pm2.keymetrics.io/

Where do I put front-end code in my backend project and how/when to run it?

The question is, say I have written a backend REST service using Python, and then some other guy wrote some frontend code in Angular JS. Is the typical workflow putting them into two separate folders and run them separately? So the process will look like below
python manage.py runserver
in Python colder and then probably
# in the angular2 folder
npm start
Or should I place all the JS code into some assets folder and when I start my server, all the JS code will run automatically with them? If so, how should I do it?
Another question related is, when is all the JS code sent to users’ browsers? If the app is a client-side rendering app, is the code sent to browser at the first time of server requesting? How does the server know it should package your JS code and ship it?
Q)The question is, say I have written a backend REST service using Python, and then some other guy wrote some frontend code in Angular JS. Is the typical workflow putting them into two separate folders and run them separately?
Both Angular and Python can be run differently as well as together.
You could choose to place the Angular files (which qualify for all practical purposes as public files) in the public (or related folder) depending on which framework you're using - Django, Flask, Web2py or so on.
You can also choose to run them independently as standalone apps.
Depends on your requirement. Honestly, there are so many ways to answer this question.
Q)Or should I place all the JS code into some assets folder and when I start my server, all the JS code will run automatically with them? If so, how should I do it?
If you place everything in your assets folder, then as soon as the home route or any other route is made a request for [from a browser] , the public folder passes on to the browser.
Although I'm not sure if it is the case with server side rendering.
If you're using Angular 1, I do not think it fits server side rendering although you could use some libraries out there.
Q)Another question related is, when is all the JS code sent to users’ browsers? If the app is a client-side rendering app, is the code sent to browser at the first time of server requesting? How does the server know it should package your JS code and ship it?
All the files in PUBLIC folder on the server are accessible by a browser.
All of your questions seem to essentially ask the same question.
There are many approaches to this problem.
If infrastructure management is difficult for you, than maybe it's easier to place them in the same server. You can create another directory and place your html that is served to browser with your JavaScript code.
In case you have a good pipeline (which I think it pays for it self) than having another server that serves your application is better. You can do more things without affecting your service, like caching etc. And your server that runs your service wont be busy serving assets as well.
I have a case where we run a node server, which serves the html and javascript to our users, because that way we can do server side rendering.enter link description here
The flow of code execution will be this : Once the browser of your user hits the server that is serving html and assets, it will download it locally and it will start with JavaScript execution (Parsing, Compiling and Executing). Your JavaScript app might do some API calls upon initialization or it might not, but your service will be executed only if frontend makes a request.
As for CORS it is irrelevant how you serve them, because you can keep them always in the same domain.

Advice on building a server connected android app

I'm creating a personal project, an Android application, where user sign ins via a server are essentially. Also users will be able to share important "updates" in both a data stream that all users can have access to, and potentially down the line a data stream that will be specific to local users.
Unfortunately I have basically no idea of how to implement the server for this application. I'm confident that I'll be able to create a solution though, I just need to be pointed in the right direction. Are there any existing servers/api's that I could access that will allow me to handle my "connected" tasks? If I were to make a server myself for this application where should I start?
If you have absolutely no experience with server side coding, you should start with PHP and MySQL to create a simple API for your app.
For getting started download the XAMPP bundle that has everything you need.
SQL and PHP are fairly easy for beginners. On the client(Android) side use Volley as it is simple to understand.
However if you want to get started with Node.js, your server can be up in a few minutes with express.js

How run Javascript on server side in Ruby on Rails

I intend to program a Bitcoin related Web application with Ruby on Rails.
Now there are some very useful libraries out there like Bitcoinjs or Bitcore that are written in Javascript and can be run on the client side in the Webbrowser, or server side with Node.js. However, since I intend to program this application with RoR, I wonder how I can take advantage of those libraries on the server side.
Is there a way (i.e. a gem) that allows interpreting Javascript on the server or can I start a Node.js instance in my RoR code by which I can then interpret those javascript libraries and execute their functions?
Any help is greatly appreciated.
Since it seams like you are very determined to use these nodejs libraries, here is how I would go about doing it. Since it is a very bad idea to run code in the wrong environment, I would instead make a setup like this.
Front end, ERB template => RoR server => nodeJs server
The idea behind this setup is that RoR is more like a task master and nodeJs is the worker. Your RoR app would figure out what needs to happen and then tell nodeJs to do it. Nodejs would then respond with the result which RoR would present back to the user. Here is an example:
Someone on the front end asks you app to transfer x bitcoins to someone else. Your Ruby on Rails app would then do whatever non bitcoin tasks were needed(ex: logging in, messaging people). Then your RoR app would send a request to the nodeJs server which would actually do the bitcoin tasks.
Here is how you would go about implimenting this setup.
Make the front end
Connect frontend actions with your RoR controllers
Make a RESTful HTTP API on your nodeJs.
If you don't already know what a RESTful API is, research it. It is a whole separate topic
Make an entry point for each action you want your app to perform.
Make this nodeJs server run localy, so people can not access it without going through your RoR app
Then use something like restful-client to use you nodeJs API from your RoR app

Categories

Resources