Meteor.js is a framework for JavaScript that allows us to write JavaScript code reusable in both client and server-side. Whereas, pm2-meteor is a CLI tool that will establish the Meteor app as a Node.js bundle and run with PM2.
![](http://findnerd.s3.amazonaws.com/imagedata/7974/7974.png)
I have seen many developers face issues in deploying the code in meteor.js. Some of my colleagues have asked for my help on several occasions. This gave a birth to an idea of creating a blog post for the same. So without further ado, let me share an effective solution in easy steps to deploy code with only one command :)
Note:After reading this blog, you’ll be able to learn following things:
- How to install node.js through command prompt?
- How to install npm ?
- How to install pm2 ?
- How to install nginx ?
- How to install pm2-meteor ?
- How to deploy code with pm2-meteor ?
Requirements: Before you start the pm2-meteor setup and configuration, you must have these things in your host:
Install nodejs and npm
$ ssh host
$ sudo apt-get install nodejs
$ sudo apt-get install npm
Install pm2
$ sudo npm i -g pm2
Install nginx
$ sudo apt-get install nginx
Here is a step by step guide to learn ways to deploy your code either from local environment or from any git account.
Step1: Firstly, on the host you have to configure nginx to use ssl and redirection to meteor port. The whole process of setting Nginx in host is given here
Step2: Mogodb setup in host / Install MongoDB server
$ sudo apt-get install mongodb-server
Step3: Setup local system
- Install pm2-meteor in local
$ npm i pm2-meteor -g
- Create pm2-meteor config file in json extension that will execute to deploy the code to server. Here I am creating a folder in project and putting the json file there.
$ cd path-to-meteor-app
$ mkdir .deployment && cd .deployment
- Init pm2-meteor setting file
$ pm2-meteor init
- Edit the created pm2-meteor.json in the .deployment folder
{
"appName": "meteor-app",
"appLocation": {
"local": "path-to-meteor-app"
},
// Path to the meteor settings
"meteorSettingsLocation": "path-to-meteor-app/settings.json",
"meteorBuildFlags": "--architecture os.linux.x86_64",
"env": {
"ROOT_URL": "https://example.com",
"PORT": 8000,
"MONGO_URL": "mongodb://mongodbuser:**password**@27017/meteor-app"
},
"server": {
"host": "example.com",
"username": "ubuntu",
"pem": "~/.ssh/my-key.pem",
"deploymentDir": "/home/ubuntu/meteor-apps",
"loadProfile": "",
"exec_mode": "cluster_mode",
"instances": 2
}
}
Step 4: Use deploy command of pm2-meteor from local to deploy, for this you have to go to your .deployment folder and run the following command:
$ pm2-meteor deploy
Above command will deploy your code to server.
Hope you like the blog. Feel free to share your feedback and comments in the comment section below.
0 Comment(s)