How to see my Compute Engine app in my browser? - node.js

I have created a virtual machine on Compute Engine of Google Cloud and I want to host my project made in Node and Angular on that virtual machine. I installed Node on the server and cloned my project from Git, its working perfectly.
My question is, how do I bring that project in the browser?

You should: npm run build. After that you could find dist folder with your project and copy content of this folder to any static web server (GitHub pages and etc)
Additional info

As Rajesh said in a previous answer, your question is a bit ambiguous. I think that maybe what you are asking is for a way to allow http/https traffic to your Google Compute Engine instance. Please feel free to correct me if I’m wrong.
If my assumption is correct, you need two things here. The first one is a public IP for your instance and the second is create firewall rules to allow this kind of traffic from internet to your instance.

Related

How to deploy a React + Express app on a local network?

This is my first post here, let me know if I do it wrong. I would like to start by mentioning that I'm kind of a beginner developer. I've had a bunch of classes, but it's also my first time working on something of my own, from beginning to end (emphasis on "end").
I'm working on a relatively simple app, for user management (CRUD, with different levels of authorizations) and shop management. I was given the choice of the tools, framework, language, etc, to use, with the only constraints that 1/ the main device to use it will be a tablet most of the times 2/ nothing should be hosted online. I wanted to get more familiar with Javascript so I went with creating a React app (front) with Express Nodejs (back) and a MySQL database I access via Sequelize.
Development is going fine (for the most part thanks to many great posts here on SO), but I just got hit by the reality that I have never tried to build the app and see if it runs the way I intend. And I do not know how to do it. I should have researched that earlier.
So far, in development I always tested everything on PC and phone by running npm start (front end) and node server.js (back end), and the client runs in a browser (when using a phone I access the IP adress and port, like 192.168.x.x:3000). Backend listens to the 8080 port no prob, access to the MySQL database works as intended thanks to Sequelize. Frontend listens to port 3000 to display the user interface on the browser, and React makes it easy to develop features in front, and quickly troubleshoot them. Everything works fine, and as expected, anyone in the same network (and with a web browser) can access and use the app that way.
This is the behavior I want to replicate with a production build : having a computer host the build, and run the "server" so that the app is available to any device in the local network. So I guess I need to somehow make my build in a way to make it possible to turn on and off the "server" at will, maybe via a .exe ? Or turn it on at the same time as the computer ?
I know I should have researched that earlier and not doing so was a mistake. All I know is I'll have to use npm run build, to get the build folder, but I don't know what to do from there. Could you help me figure it out ? Among many things I'm not sure of, is whether or not the host computer (not mine) needs to have node.js installed ? Does it also have to have MySQL installed ? Do I make a single build that incorporates the backend and the frontend, or do I build both separately ? If so, how ?
Let me know if you need to see part of the code. Thanks in advance and have a great day.
EDIT : App was created using create react app
There are options to deploy on cloud like Cloud Servers. But I think you're looking for hosting the application on the local machine. You need to create a service, bundle the application and serve whenever you want.
Following link might be helpful
https://www.section.io/engineering-education/compile-your-nodejs-application-into-a-exe-file/

How to hot reload on netlify?

Netlify just as example, same question with CloudFlare Pages etc.
In the past I setup my own server with node and react/vue.
I have my node setup on a server because I don't want to install node and node packages on my local machine.
When I was developing I SSH into the server with port forwarding.
So I ran a dev server on port 8888 (npm run dev) on the server and opened http://localhost:8888 in my local browser.
When I make a change to the files I can immediately see the effects without running npm run build.
I am thinking about using a service like netlify because its the right thing to do? But how can I see the changes I make without actually running build?
Is this even possible or do you use theses service only when you are building a website that rarely changes? I am probably missing something. But not sure how to proceed.
I don't know what's the right way. I am very open to suggestions.
Edit: These services that I mentioned are meant for build only. See answer below. I am still leaving this question so people can post suggestions.
You cannot do this. Those services are only for hosting the build version of your app. You have to develop it locally and push the build to these services.
Why would you even want to run a development version online?

500 error when I try to deploy nextjs ssg application with incremental-static-generation

I have NextJS app with SSG. This functionality was added recently and according to it I should do next-export after next-build to get static files. But after appearing in 9.4 of Incremental Static Regeneration I need to keep server on by npm-start command (in my case I use custom server file with next-express functionality). It works good locally and It works good when I get artifact from Azure. But It doesn't work globally when it will be deployed finally. Help please
Through my attempts, I found that it is impossible to install globally or use next in Azure Web App. That is, it cannot be deployed through Github.Deploying using other methods such as FTP cannot run successfully. It should be related to the azure node environment.
But the method provided in this post says that it can be processed by adding web.config. I think it should be useful and helpful to you. Please read it carefully and try it.
You also can read this document, maybe it useful to you.

Ghost blog integrated with application

I am new to node, so please excuse me if I am asking stupid questions.
Ghost has been released as NPM module recently. I am trying to integrate it with my application, so I could have custom home page and serve blog on a separate page. Once I do following in my app.js, it takes over all the traffic to my site. How do I configure ghost to serve only the blog?
var ghost = require('ghost');
ghost();
We're missing a few details here so I'll make some assumptions.
If you are hosting node using the default server than (as of this posting) you are out of luck since ghost is setup to run in it's own standalone server. One possible solution is to run both the standard node.js server for your page then another for ghost. That's obviously not ideal but until they fix their integration issues you don't have much choice.
I'm trying to solve the same problem, and currently imagine finding a hosting that allows me to run two node instances (I think that is quite possible with e.g. digital ocean). One - port 80 - will point to Ghost, while the other (on some other port) will host the REST API for the app.
I will then create a blank page linked to a custom template that loads the rest of my angular application - the files will be stored in the assets folder of my custom template, while ajax calls will simply be to the non-standard port.

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