Deploying Node JS application over a server - javascript

I have done quite a research of deploying an application over the local server that I have on my machine. Each source code for the Node JS application or the example that is available over the internet specifies to run the application from the console.
Is there any way that i can configure my MAMP server so that when i hit a URL the Node code specified is executed.
Are there any parameters to set for the same ?
I looking forward to the steps to achieve this as i was not able to found a relevant answer for the same as such.

Related

Excel Javascript Add-in Deployment On Local Network

I have developed an Excel Javascript Add-in on my machine using the yeoman generator. The add-in itself works fine when I start it up on my client with npm start. I can use the add-in on any port I want provided I change all the ports in the config files etc. However, we now want to delpoy this add-in on our local server to make it available to several users.
I have noticed that every time I change the location of the project e.g. from my machine to the server the application will start up but Excel will give me the error message "ADD-IN ERROR Sorry, we can't load the add-in. Please make sure you have network and/or Internet connectivity. Click "Retry" once you are back online". My work around for now is to create a new app on the server and copy the html, js and css file to the taskpane folder. When I now start up the new app it'll work fine.
For the second issue I haven't found a solution/understood the behaviour. When I create an app with the yeoman generator on our server (MS server 2019) and start it up it can be reached via e.g. localhost:3000 on the server but not via :3000 or :3000. It runs fine when I access it from the server itself.
I have opened the inbound and outbound port 3000 on the server to allow https communication. In a next step I added the manifest to the windows 365 admin console and added myself as user. When I open Excel from my machine (client side) the excel add-in will be available in the insert ribbon but won't load and I get the same error message as described above "ADD-IN ERROR Sorry, we can't load the add-in. Please make sure you have network and/or Internet connectivity. Click "Retry" once you are back online"
The following troubleshooting steps have been performed. I checked whether I can reach the add-in url via web browser but the connection timed out. When I check on the server side whether the app is listening I get the below result.
TCP 127.0.0.1:3000 0.0.0.0 Listening 40776
I'm not sure but I think the app should list on e.g. 0.0.0.0:3000 to capture inbound traffic from the client side. Is there a way to change this add-in (app) behaviour on the server when creating/starting up the app with the yeoman generator? I have checked the webpack.config.js file but I couldn't find any way to change that behaviour.
Any idea/help is appreciated.
Thanks!
I believe this is precisely the intended configuration of the yeoman development environment. It spins up the webpack dev (NodeJS) server, which by default only listens to the localhost / loopback address.
From here:
https://webpack.js.org/configuration/dev-server/#devserverhost
It looks like you could hand modify your webpack.config.js file to include a
host: '0.0.0.0' entry under the devServer listing.
The other item you might need to change is
https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
As I believe this defaults to 'auto' which would only allow connections from the local computer.

How to give the server port to client

I have a node server with several node projects. I use nginx to get them all responding on port 80. Now, this works for the initial http request. For the websockets, I need to use the direct server port. To keep everything alive while developing I would like to try this, projects will have a dev and live version. Once de dev is stable, I will copy it to the live folder. The live folder is runned by a systemctl script where I define a difrent port to the live version so I can dev without taking the live down. The problem I encounter now is, how can I get the running server port in my client side Javascript so that the dev page connect to the dev port and visa versa?
currently I'm only using express, socket.io and mysql. I have no further npm packages installed. I searched allot but there is not to mush I can find. I found how to connect the socket to the page url but I cannot use that because that URL will always be on port 80. Further I found allot of huge packages that has no use for me since the original page is just static, the dynamics all run over websockets.
Is there any way to parse the port number in the clients .js file like I could do fairly easy in php? And if so, what would be the most efficient way. I could let javascript check if the page uses the live or dev URL but I would prefer not to hardcode my dev URL into JS where it is for everyone to see.
run a third node.js socket.io server program, all your clients connect to this server first.
In this simple node.js program, determine the type of clients by any means. e.g. different user id for dev/production users
send the server url and port to your client according to its type (dev or production)
you may also use this technique to separate your users to different production servers.

Angular 4 SEO Friendly solution in prod

I'm trying to create a website in Angular 4. It is a base of my personal study.
My website is up and running but I'm trying to improve it. I checked and apparently my website is not SEO Friendly. I make some changes and I discovered this sample https://oliverveits.wordpress.com/2017/07/05/server-side-rendering-in-angular-4-with-universal/ That show an Angular 4 app with Page Source code.
I make the changes, I started to use Webpack and other features sugared by in the link. When I run the command "npm run start" and I access http://localhost:8000 I can see the Page Source. But when I copy the dist to my server on Godaddy domain I can't.
I'm not sure about what I have to do. If I need put my website in a node.js server or if I'm not compiling it correctly to have what I'm expecting.
I'm open to different approachs.
Well, I found the what causes this issue.
I think many of new Angular devs possible have the same problem.
When you run "npm start" or "ng s" what are you doing is put the node to listen a specific port. In other words, you are running a node server.
In another approach, copy the files to an IIS server or Apache Server. This doesn't make the Node Server run. In this scenario, the pages are download to the client browser and run as HTML/javascript page. And because of this when I try to see the Page source I saw the Angular files.
Took me a while to understand it. My background is .Net development.
Now a day my website is running in one of the many node.js servers. evennode.com, on this server instead of to have an IIS or Apache, they set up a Node Server to listing a specific port and then you are able to run all your development on the server side.
I found easier use a node js server like evennode them set tup node js run on my Goddady account.

Is there a way to run a Node.js application within a Tomcat server?

I have a REST Web Service running within Tomcat and I do not want to run the Node.js application manually. Can I somehow run my Node application using Tomcat?
You cannot run Nodejs server inside tomcat.
I would suggest to ge to http://nodejs.org/ and read some docs and refer some videos.
I have used openshift to host my node js application
please refer this link to know more about where to host nodejs application

Can Node.js be run within Tomcat server?

From what I have read so far in this blog http://nowjs.com/ I need to install nodejs in the server machine for it to work. But, I am using a shared server and don't really have any authority to put something into the server machine.
Putting it into the container(tomcat) is however another thing which I mostly do.
Generally speaking, when we say server we mean tomcat or websphere or jboss.
But with nodejs if I am not wrong server means the real machine on which tomcat etc. runs.
So is there any way I can run the nodejs server inside tomcat server or am I thinking about it the wrong way ?
Yes, you are thinking of it it the wrong way. The key feature of Nodejs is that it contains, amongst other things, a rather natty embedded HTTP server. Think Jetty. However it might be possible now or in the future to run JavaScript in tomcat.
I recommend going to http://nodejs.org/ and watching the video, it will surely clear the matter up for you.
Meanwhile I would recommend getting hosting which includes SSH access, and preferably root access. Root access will make installing node a whole load easier and allow you to run it on a commonly used port (avoid running node as root, use port mapping) . But you don't need a seperate web server to get started, you can install Node.js on windows, mac and linux.

Categories