How to depoly a Node.js app [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have installed npm locally and used it to install Bower, Grunt, Polymer & Yeoman. But I am still a little confused as to what Node.js actually is.
Back in the day I used to setup an Apache server locally, install phpMyAdmin and get to work on my project. I could then take the SQL database & the entire file directory for my project that included php, html, css etc. files and upload to my server and it would run.
I have noticed that PHP is not the way to go anymore, and that everyone seams to be running JS frameworks like Angular, Backbone & Ember, also Polymer looks interesting but I am not sure if it's a framework.
So my question is how do I deploy something built with node.js? e.g. a dashboard website/app built in Angular, Backbone, Ember or Polymer.
I am also guessing that SQL would not be the way to go anymore, but a noSQL option would be, such as PouchDB or Mongo? I really don't know how people like to store data with these new frameworks, maybe they still use SQL?
Can I simply copy the process of PHP & SQL and upload the SQL database & then the file dir and it will run on the server?
I have used firebase to deploy a polymer website/app, but I would like to know if I could use a standard web host instead of firebase or heroku.

There are 2 common ways to go about this. You can think of them in terms of client app and server app.
Server
If you're just creating a Node.js server, you may want to use the library Express (which is a wrapper around Node.js's http) in order to initialize a server. Then when you upload your source code to, say, AWS EC2 or Heroku (just as an example), you tell your startup script to invoke your server (if you server initialization code is in ./server.js, for example, you'd tell your EC2 or Heroku script to run node server.js).
Client app
There are a lot of tools to compile client apps (static sites), many of which work with Node.js: for example, Bower and Webpack. In this case, Node.js is only responsible for running this build tools and compiling your app for you. Then, it's as simply as copying the compiled static files into your hosting provider (like AWS S3, for example). Outside of the scope of the answer, but you can use continuous integration tools like Codeship or CircleCI in order to compile and upload those static files to your hosting provider automatically.
Hybrid
If you want Heroku to serve a static site, you can set it up in a way where Node.js is actually running a server that serves static files. This is a combination of the 2 approaches above because you need to actually be running an http server inside of Node.js that is responsible for serving your static content. You can also have an API server embedded in the same place, but a common practice is to have a separate API server somewhere else (separation of concerns).
A couple additional comments:
SQL would not be the way to go anymore, but a noSQL option would be, such as PouchDB or Mongo?
False. SQL and NoSQL both have their benefits. This is out of scope, but on a high-level, there are differences between schemas (whether maintained on the database server or the client server), operations likes joins, etc. (which plays into scalability), and the features of each individual database provider: for example, Redshift is a SQL database based on Postgres that uses columnar storage which is good for running, say, sum operations across gigantic datasets. There are Node.js drivers for it, you just have to pick your poison.
I would like to know if I could use a standard web host instead of firebase or heroku.
I wouldn't refer to a host using the term "standard", as essentially all hosting providers do the same thing: serve content. If you're using Node.js, you have many choices for hosting providers: AWS S3, AWS EC2, Heroku, Bluehost, and myriad other providers.

I don't think you can simply copy the files unless you write a script that will automatically call npm init (or whatever your startup scripts are) when the files have changed.
As long as you have shell access on your server you can probably use Apache or nginx as a reverse proxy for your node app, and set up a push-to-deploy system with git fairly easily.

Related

Setting host and port when executing a .jar

I have an Angular + Spring Boot app that's deployed as a single .jar file, some .properties files and a bash script to execute the .jar depending on what properties we want to use.
Right now, my .ts classes have host and port set statically, e.g.:
const PATH: string = 'http://localhost:8080/(...)';
Is there a way to set them dynamically while executing the .jar?
The question is very broad and could not be answered definitely with such minimal information. I want to point some things though which you must consider in what ever solution you apply to this problem.
The backend which is a spring boot app, may as well run in localhost:8080 and that is fine. It is never however the case that an application backend is in the same machine as the Frontend. You have adopted angular as your frontend which means by default (if you haven't overridden this behavior) some static files would be served and executed in the browser of the end user.
So this in most cases means that the end user must know the ip-address or domain so that he can reach the machine that runs the backend server.
So the end situation you will have is backend running in for example localhost:8080 in some VM and frontend using a property like const PATH: string = 'http://my-backend-domain.com:8080/(...)'; so that an external user can reach the backend server from his browser.
In a very simplified scenario an effective solution would be to adapt your angular app with this answer then during deployment decide what is the domain for example where you are deploying the app like /my-backend-domain.com and go to assets/data/config.json and configure it there. This would not require any additional build of Frontend just a simple configuration.
There are many ways to do it
environmental variables
application arguments CommandLineRunner
configuration file

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.

Reading and writing client files from a web application

I need to implement a mechanism in order for a remote web application to communicate with a local desktop (WinForms) application that I cannot modify nor have the source of (except by decompiling). This happens by writing a file to the temporary folder that the desktop application will consume, and waiting for that application to "return" by writing another file into temp folder. Folder has to be temp folder.
Question
Is there a Javascript way to access the file system in a non sandboxed way, even by setting specific browser configuration options?
Environment
The application runs on a private LAN where all computers trust each other within the same AD domain. Plus we are theoretically allowed to map any network drive on any computer. Working in the trust zone, we don't have to care about most security concerns.
Background explanation
I have a PowerBuilder desktop application that I need to "port" to web (using J2EE) and install to a separate server, local to the same LAN. This application (named GP) currently starts a process of the child application (GC) that will not show any UI, instead it will listen for two files on a temporary directory.
When GP needs to open a window from the GC process, it will write two files: GP_to_GC.txt with a syntax I have documentation of, and GP_to_GC.flg that serves as flag file. GC will delete both after retaining and parsing the content of txt file, thus showing the appropriate UI form based on input.
The "return" is exactly the opposite. GC will write a pair of GC_to_GP files to temp and GP will refresh its views.
How can I do this with JavaScript?
Based on what I'm reading, you are porting a Desktop based Java EE application to a web application? If so, then you can continue using Java and access the folder that way; no need to use JavaScript.
What is unclear is that you're saying you can't modify anything, yet you're trying to port an application. Which is it?
If you can't modify anything, and the only thing you can do is drop JavaScript into an existing web application, then your solution is rather simple:
Create an HTTP API application that sits somewhere that has access to those folders, and issue a POST request to that API that will then read and write to the file system. It can be in any server side language you choose: Javascript (Node.js), C#, Java, PHP, whatever. It simply needs the ability to access the file system through the webserver, and most frameworks provide that capability.
I can't give you any code because you haven't mentioned which server side language you want to use to accomplish this approach.

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

PostgreSQL connection via javascript

I am searching for a way to connect to postgresql directly in the browser. Im trying to utilize nodejs and browserify but have had no luck so far with the bundling. Whenever I compile a script that contains a
require('pg')
it specifically states in the browser:
Cannot find module '/node_modules/pg/lib/client'
the browser tells me afterwards that he is not able to find the modules that pg requires. Maybe i need to bundle pg with browserify before ?
I appreciate if somebody has an idea on how to work on this or even a suggestion how I could connect via javascript to pgsql.
While some node modules may be generally reusable to some degree in a web browser, most take advantage of Node.JS specific features or drivers and cannot work in any web browser. A case like a Postgresql package is a perfect example, as it requires many functions simply not present in a web browser.
If you look at the APIs of Node.JS (http://nodejs.org/api/), these APIs are not available in the browser (some could be emulated, but many are file system, low level sockets, binary modules, etc.).
If you want to use Postgresql, you'll need to build a web server layer, and expose an API of your own (likely a RESTful style api) and call the web services to perform the database actions you want to use. You could look at using Connect or Express to make writing the web service layer more convenient.

Categories

Resources