how to deploy nodejs rest api with express framework on production server windows - node.js

I have created a node.js rest api created using express framework for routing. I have used tutorial
Now I want to deploy that rest api on actual production server. How to achieve that thing.
I have gone through below links.
Deploy node js application with express framework on production mode --- Only for linux. I need for windows.
Deploying NodeJs Express Rest API to Windows 10 IoT -- a little bit similar problem but no solution
https://stackoverflow.com/a/38652869/2810015 -- this said to run npm start on production server after copying all of the files on server. But this is not working fine either.
Any help will be highly useful.

You use pm2?
Usually I use it to start the application. It works for both windows and linux. He leaves the service initated, and in case something happens that knocks the service up again.
You install it on the server, and instead of using it
node server.js
You use the command below
pm2 server.js start
Link: http://pm2.keymetrics.io/docs/advanced/pm2-module-system/

Related

how to deploy an ionic-react app to mobile if I'm using node js server in the backend?

I discovered ionic this week and I'm really considering using it at work.
Basically, my goal is to build an app that will work on android and Ios, where the needed functionality is to connect to the cloud over web socket and pull data from the cloud and show it on my phone. Maybe later I'll eventually need to consider using login but not for now at least.
Normally, if I'm building a web app. I ll use nodejs to pull the data from the cloud and expose it to the frontend. I ll write all code together and I ll host my app in Heroku or something where the entry point is my nodejs server right? So that my server needs to start and it will take care of the rest.
This is a bit confusing in ionic since I need to start the app with ionic serve, but somehow I also need to start my nodejs server too right? So I assume I can't write the server-side code inside the ionic app or am I wrong?
There is not much about this on the internet but I did some research and I guess that I should deploy (host) my nodejs server in the cloud (maybe using Heroku) and then connect to the server from my mobile app over the socket. Is this the right/only way to do this? are there any security issues with this method?
I find ionic great but I'm not sure if I should use it at work. Sincerely, this use case of using a backend server with ionic made me confused.
Ionic looks ideal for building cross-platform apps that does not need server-side scripting, but how complex can it be if I want to integrate some server-side code in my app? especially as I said I'm going to use some login forms in the future to extend the functionality of my app.
PS: I'm using ionic 6.10.1 and specifically I'm interested in using ionic with react not with angular.
After some search, I discovered that it isn't possible to deploy the frontend and backend code together. Therefore the trick is to deploy the nodejs server separate from the frontend.
Precisely, if it is a web app, then you should deploy the nodejs server in a separate host from the frontend. Then by starting the frontend app, you can communicate with the running nodejs server via socket or REST API.
Hope this helps someone in the future :)

Chatbot using Api.ai nodejs angular socket.io

I have been using api.ai javascript SDK on angular to build my chat app to integrate it with the website. As this javascript sfk is deprecated I am now exploring to build the same on Node JS SDK with socket.io for real-time experience and angular for client features...
Currently, I'm following the below link to build my chat app
https://codingblast.com/chat-application-angular-socket-io/
As I am very new to Node I have lots of doubt like...
How to deploy my node and angular app on a server to host it on my website
Angular and node can it be deployed as a simple app.. if so what are the steps and how could I achieve it.
Is node is possible ti have multi threading as many users might chat with my chatbot in parallel before on angular it will be acheived by session id.. but how it is possible on the node?
Is it fine to deploy my node app on my existing apache server or should I use separate server
How can I host multiple node js chat app on a single server since each app will use a port... how much it is possible...
Which server is recommended for node deployment windows ubuntu or Linux.
Please help me...
Angular Apps are static files that can be served using any server. For NodeJS, you will need a server that supports NodeJS runtime execution environment. A simple cloud server will do. (AWS or others that you may prefer)
Angular runs on the client-side, NodeJS runs on the server-side, there is no "Simple App Deployment" (as far as I've known). You need to run the NodeJS server code which will server the REST API, and send the Angular deployment files to the client with some file server. (Even the NodeJS server can do it)
"Node.js is a single threaded language which in background uses multiple threads to execute asynchronous code" [Source]
But you can use "fork" to run parallel tasks. For chatbot, you may consider using WebSockets.
It is possible to run NodeJS with Apache server, but how you want to deploy it depends on your decision and architecture. See HERE for more information.
Link in no. 4 should have answer this this.
NodeJS can be deployed on both Windows and Linux(Ubuntu) environment. It depends on how much you can spend, and how much benefit that expenditure will bring you. (Linux server operating systems are totally free, Windows servers aren't)

Deploying React & Node.JS as a service Linux Ubuntu 14

Have a Node.Js API and a React app semi finished. Working on deploying to get the development cycle churning. Currently using npm start for viewing the react server during development. Same for the Node API. When deployed to AWS EC2 I am building in the most basic fashion, npm build pushing to a 'release' folder.
Once the deploy folder is up, I can go into it and run serve -s release
This gets me up and running. I can do the same for api server.
To get the apps running as a service, for the api, I can see how I can build a systemd process and run that with no issue.
For the react app, is there an easy way to run that server as a system... I'm new to this stack, so I might be confused. I have read in some places that once you've built your react app that you need to serve it out via apache or nginx? (e.g. in development it hosts itself, in production, you need to serve it) Is that sort of the general idea - build with local hosting, deploy with a production webhost?
Help appreciated. This is my last major issue before I can get Jenkins running a nice pipeline for deployment. Thanks!
Since you are already running a NodeJs server, It would be a good idea to host your ReactJs App in the NodeJs App itself.
You can pipline in the Jenkins to Build the ReactJs App first and the move it to static serving folder in the server and then you just need to deploy the NodeJs app in which ever environment that you want.

Best way to implement Angular Universal

I suffer a lot in the past with angular apps and social media, so I'm glad to see that Angular Universal is being developed.
Currently I have some apps that are Angular4 as front end, and Java with Spring as backend. As far as I know there are some ways to implement Angular Universal here but they seem pretty complex (at least is what I read). So I want to know if that is in that way or not...
But anyway, my main question here, is because I saw that in order to implement Angular Universal we should have (ideally) to make the backend with nodejs, how to structure these two technologies, I mean... Should I have Angular app as a frontend app and Nodejs app as a totally different backend app (just like Java) where both are connected with web services? Or should I served Angular4 SPA direcly from Nodejs views?
And where should I place Angular Universal here?
Now that Angular CLI v1.6 is out, there's native support for building Angular Universal into your projects easily using Node.js! Essentially, you would ng build --prod to create a dist/ folder, and then create a simple node back-end and connect to your dist/ folder containing your front-end code. This article gives a great step-by-step guide: Angular server-side rendering in Node with Express Universal Engine.
When you use Angular Universal, it is going to be a single process (Operating system process) that hosts and serves your Angular pages.
In production you may have multiple such processes behind a load-balancer.
Your back-end APIs (if developed in Javascript) may be hosted in the same Node server or in separate server.
The Angular Universal setup steps are detailed here in the official documentation.
However, I had a few wasted hours to find out the following point
Webpack 3 is not compatible with ts-loader versions higher than 3.5.0. At the time of developing this, the latest version of Angular CLI is 1.7.2 which uses Webpack 3.*. Hence, while setting up Angular Universal, install ts-config#3.5.0
Finally, here I have a seed project for Angular Universal. It uses Vagrant to locally setup the development environment. Also, by tweaking an environment variable in your local host machine, you can run it in a production mode in a Docker container. The steps to run it are detailed in the readme file.
If you refer to my Dockerfile in the above Github link, its entrypoint reads:
ENTRYPOINT ["pm2-runtime","start","/home/aus/dist/server.js"]
So, you see, it's just a singe command, and your app is up and running at port 4000. Of course you can use other command line parameters to provide memory limit, port and so on.

Deploy Node JS REST APi Mongo DB on Windows

I'm new to node js. In the last months, i developed a REST API using node js, Express and Mongo DB for my customer.
I would like to deploy the WEB API on Linux, but now my customer asks me to deploy the solution into a Production Environment with Windows Server 2008 / 2012 R2.
Which is the best way to deploy this solution on Windows Server?
There is some best guide to see?
Thanks
PM2 on Windows:
Personally I am using pm2 on my linux machines. Pm2 is a process manager for node apps, which makes deployment and maintainance of your node applications a lot easier. You can also use pm2 on windows, see: https://github.com/Unitech/pm2
You need to make sure pm2 start upon restarts / server crashes and therefore you want to setup a service. You could take a look at: https://github.com/jon-hall/pm2-windows-service which may be a help for that purpose.
Docker:
If you are just struggling because it's windows and you are still looking for your "common deploy methods" you could still setup a docker container with your favourite environment. However if you don't have experience with it, it is probably a bad idea to test it first in a customer project.

Resources