How to deploy Node.js REST API to production mode - javascript

I've created a REST API using Node.js and Express, so now I need to share it and publish it on a server in order to connect from Front-end.
Can you tell me a proper way to do it?

You could use Heroku for deployment, this way you can know how your app will fare. It's free moreover.
If you're satisfied with it then you can go ahead and buy a dyno or use other platforms like Azure or AWS.
To learn more on how to deploy your existing app to Heroku, visit this page.

The question you are asking is very broad. It can be done in a lot of ways. For me this 2 part tutorial was very helpful:
https://hackernoon.com/tutorial-creating-and-managing-a-node-js-server-on-aws-part-1-d67367ac5171. However, this only covers the installation on AWS EC2. This doesn't differ much from deploying it to Google Cloud, Azure or something local.
In general you need to fix the following steps:
1) Create a server somewhere (local or in the cloud)
2) Install all the stuff to run your app. In your case Node.js at least
3) Put a copy of your app on the server
4) Run it with node
5) Go to the ip of the server
The tutorial gives more details. DISCLAIMER: If you actually want to use this in production there is way more to consider. For example, security policies, setting up proxies, installing certificates etc. Please read up on that properly before you start running production apps.

You can install node on the the production server and then where the project is situated just .
copy that path
Open the Cmd >>
Enter "cd copied path .>>enter
you npm will be install & REST Api will Work.

Related

Publishing website along with nodejs backend and mysql database

Ok this my sound silly but i have no clue on how to publish node.js backend for website i made. I am new at this and i know how to publish a website there are plenty of websites that offer hosting and domain for some amount of money but i don't know about backend. For example let's say i have node.js backend that reads data from MySQL database and sends it to my local-hosted website. And let's say i have nodemon package installed so i run it with nodemon and everything works fine. My question is how to publish this nodejs app along with my website and database.
You should get a VPS (Virtual Private Server) with Docker, It is the best solution.
Just copy your node folder and put it on a node docker image!
Got html front end? Just put it on an nginx docker image.
MySQL too, almost everything is possible with docker!
Want to learn more about docker? Here
Look into Heroku. Easy to use, mantain and deploy. You could either deploy from GitHub repo or directly via heroku.
Look into it here [https://devcenter.heroku.com/articles/deploying-nodejs]

How to deploy Javascript app that runs from command line?

I have a simple CLI application written in Javascript using Node that is for internal use by a small team. It runs in the Linux terminal as a CLI app. The app consists of a single ".js" file and requires a few Node packages. The problem I face now is how to deploy it to our internal team using a simple method that fits with our routine process of keeping end user computers updated.
Our app needs to be installed once per workstation / laptop and to be available to all users on that computer. Any user should be able to open a terminal and enter the command to run the app.
It seems a lot of people have discussed using Javascript for shell programming, but this issue of deploying the completed app is not widely discussed. I have not found anything on the topic. So far I have been recommended solutions that are appropriate for either development environments or web servers.
This app is not a web app and it is not deployed on a server. It needs to run offline. I am also not asking about developing or maintaining the app on a development workstation.
The installation process should ideally be as about simple as installing a shell script in /usr/local/bin and setting permissions so all permitted users on a computer can run it. We are looking for an installation method like this:
copy the Javascript file only once to each computer (to a location on the $PATH) and make sure the Node packages are available globally on that computer.
I specifically want to avoid having to do an npm install for each user account on each computer.
I also want to avoid having to update Node packages for each user account on each computer.
A developer will keep the app updated so it is always compatible with the latest version of the Node packages, and all computers it is deployed on will always have the latest versions of those packages installed.
One specific problem I encountered is discussed here, but the answers assume a different set of requirements (such as the need for "multiple applications running on different package versions").
For those requirements, if the actual problem is solving the EACCESS error (you should edit the question to include that information), then you should look at the permissions of all directories, and make sure that the user account that manages node packages on each computer has correct permissions.
One way to do that is to give /usr/local a special group, set the sticky bit with chmod (see man chmod), and use chgrp -R on the existing tree.
Then make the installing account a member of that group, and don't use sudo for npm install -g.
(Never using sudo for installations into /usr/local has the additional advantage that you can't accidentally install something somewhere else, for example because you didn't set paths in this local package source correctly.)
We are using these two approaches for similar deployments:
the programs live on a specific network mount. All users can run the same package from there. The developer only updates this package. No copying to local machines.
we use a simple deployment script which runs on all machines on logon. It pushes and copies the latest version to the local machine.

How to Deploy NuxtJS Project on Shared Hosting?

I developed a NuxtJS project locally and am trying to figure out how to deploy my project to a shared hosting provider list Host Gator.
I want to use the server side rendering functionality of NuxtJS so I will need to run
npm run build
But once I do that I'm not sure the correct steps to then deploy that built project to shared hosting?
As #AlexanderStaroselsky says, you will not be able to deploy successfully to shared hosting although it isn't because you can't run node, you probably can, it is because you can't run a reverse proxy once you deploy. I once foolishly tried to deploy a nuxt app to Godaddy shared hosting and it was a total nightmare.
I gained shell access and installed node and transferred all the files and ran npm run build and then npm start. All of this went fine and then was confronted with the issue of how to direct traffic to the nuxt app. On shared hosting you use a .htaccess file to direct to index.php or index.html but you need to make the rewrite rule to direct to http://localhost:3000 which you can put into your rewrite rule but it seems to block the correct functioning of the app. I was able to get the app visible but it didn't have any functionality. The routing didn't work, any images sourced through require('~/assets/images/...') didn't display and it was totally unworkable.
What you need is to be able to install nginx to set a reverse proxy and shared hosting never offers root privileges for you to be able to install it. What you need is a cloud hosting provider which gives you a virtual server with full root privileges to install nginx, node, and any other packages you might want. There are plenty of them out there that are affordable (probably more so than shared hosting) and easy to use, such as digitalocean, aws, google cloud, upcloud and so forth.
There can be a bit involved in deploying a nuxt app especially if you are using a rest api and then more so if you wish to add an ssl certificate but there is documentation out there to do it.
All that said, if by some miracle you ever find a way to successfully deploy to shared hosting let me know and I can dust off my godaddy account that I stupidly paid for several years worth of and don't use.

MeteorJS and IoT Space

I want deploy a Meteor application on a wago industrial PLC 750-8202.
Wago supports Boards Support Package with the PTXdist tooling support (Communicate with CoDeSys program on a Linux-based WAGO PFC200 PLC).
I have no idea how i can utilize meteor on such a platform.
Have you any ideas how the steps can be realized to add meteor support for wago plcs ?
It is has linux on it, just SSH to your PLC. Make sure it is connected to your local network.
Now you can install node and everything else. It is like you have your own VPS. Configure everything. You can even install ftp server and upload your files over FTP. Or create small script that will be triggered from Github hooks and update your PLC as soon as you push changes to master branch.

What's the easiest way to deploy Meteor app?

I've spent whole day and without success. I've tried Heroku with https://github.com/jordansissel/heroku-buildpack-meteor, but it gives an error and logs doesn't give any good info. I want a free service with the ability to scale once the app gets more traffic. I just want to write as few lines as possible, or just drop a bundle. It shouldn't be so difficult. Thank you.
IMO The easiest way to deploy meteor app for production is to use meteor-up and your own server (DigitalOcean, Linode,...) .
meteor-up setups server for you (install nodejs, mongodb, etc) and give you easy way to deploy:
mup deploy
You can have server good enough for start for only 5 $/month.
It doesn’t get much simpler than meteor deploy.
$ meteor deploy myapp.meteor.com
Where myapp is a not-taken subdomain of your choice.
From the documentation:
You can also deploy to your own domain. Just set up the hostname you want to use as a CNAME to origin.meteor.com, then deploy to that name.
$ meteor deploy www.myapp.com
If you want scalable, it's not going to be free (to my knowlege). But you can use AWS, linode, or pretty much any of the cloud services. Just install meteor on your host, and run this command from the project directory:
$ cd my_project_directory && meteor
If you want it to run in the background:
$ cd my_project_directory && meteor &>.log &
$ disown %1 // or whatever job number meteor runs as.
I made a few tutorial vids for using Meteor Up with Amazon EC2. You can start out with the free EC2 Micro Tier.
Setting up EC2
https://www.youtube.com/watch?v=OXdPdSekVtg&list=UUs2gDoWu9gHHR0aOklT3nvg
EC2 SSH
https://www.youtube.com/watch?v=K-IRgEge6jA&list=UUs2gDoWu9gHHR0aOklT3nvg
Meteor Deployment onto EC2
https://www.youtube.com/watch?v=Lyyh2fkXovo&list=UUs2gDoWu9gHHR0aOklT3nvg
It seems an old question by now but in case anybody stumbles upon here,
after I made my research and tried lots of different things, I ended up with the process below which includes amazing phusion passenger and I'm doing it for many projects of mine so far.
1 - Install meteor on server by doing
curl https://install.meteor.com/ | sh
2 - Install Phusion Passenger by following the documents here
3 - Build your app locally (it is important to add meteor packages)
4 - Delete .meteor/local/build and .meteor/local/cordova-build (don't delete db if you want to keep your local db)
5 - Using ftp, create a folder on your server and upload all the files including .meteor folder
6 - Run phusion passenger standalone by doing
sudo -E passenger start --port 80 --user root --environment production --daemonize --sticky-sessions
Of course, you should change the variables before doing that. You can use the last 4 steps for every app you have. If you want to publish a cordova app just use your domain with selected port instead of yourapp.meteor.com
Since meteor is reloading itself automatically until you say not to, you can just upload the new client files to server and wait the reload when you want to make a quick change. If the change is on the server, stop the passenger with
passenger stop --port 80
upload your files and run passenger again.
I hope this helps someone out there.
Best

Categories

Resources