How to deploy meteor app frontend and backend separately

Hello,

I mean meteor apps are single page apps anyway. So their front end can supposedly built/compile into pure static web to be deployed on some web server like nginx. While the backend can be deployed to nodejs server (pm2 for ex)

So I wonder if there is a way to achieve that.

Thanks

As far as I know, there’s not a way to separate the front-end and back-end of a Meteor application but there’re certain ways for you to distill the parts that you want if that makes sense.

Front-end: GitHub - frozeman/meteor-build-client: A tool to bundle the client part of a Meteor app.
Back-end:

Keep in mind DDP is just a protocol like HTTP, so you can build and host your front-end part using any technology and have it communicate with a headless Meteor application.

3 Likes

Thanks a lot for your information. Yeah, I guess it is not easy. I will try to dig deeper into that.

Just 1 more related question : assuming I deploy an meteor app (React + meteor method/DDP) with nodejs and nginx proxy, can I use nginx to cache everything except api calls? That way, it is quite similar to separate front-end and back-end

Just 1 more related question : assuming I deploy an meteor app (React + meteor method/DDP) with nodejs and nginx proxy, can I use nginx to cache everything except api calls? That way, it is quite similar to separate front-end and back-end

Just so that we’re on the same page, you’d deploy a normal Meteor application with React as a front end layer and use nginx as load balancer. Now would you be able to cache other stuff (like images and static files for example) using nginx? Sure, you can. After Meteor builds, it provides a very simple node bundle that’s Meteor-less in essence, after all Meteor is just node with some nice stuff on top of it to allow for a nicer developer experience.

https://medium.com/startup-founder-panel/deploying-a-meteor-app-with-nginx-from-scratch-1332b32e99a5

1 Like

Meteor was designed to be deployed via the build method it is shipped with. This will output a tar ball which you can upload to your server’s webroot and then unpack, install and run as a background process in screen or forever

Nginx is a great web server, and my weapon of choice. Although Apache and Lighttpd exist, as do many others out there. Any that provide proxying will work with meteor because you simply proxy the background process via it’s port to your port 80 and that’s it.

The client is served the client side portion of your meteor app. The server runs from the server portion of your app via the background process that is running on your server. Mongodb can then be run locally as to mitigate all network overhead and give a very lean, mean and powerful machine.

PHP, Python and other JS frameworks are in general, much harder to get to play ball then this, so if you’re finding it hard then you can think again because meteor is literally a handful of commands and you’re good to go.

To build and deploy you do the following:

  • Build your app: meteor build ../build --architecture os.linux.x86_64
  • Deploy it: scp ../build/app.tar.gz user@server:~/
    • (Optional Backup to instant rollback): sudo cp -R bundle bundle-backup/
  • Unpack it on server: tar -zxf app.tar.gz
  • cd into bundle directory and run install: (cd programs/server && npm install)
  • Run: node main.js (do this inside a screen and dettach ctrl+a d it so it runs in the background with screen and doesn’t close)

Important: For first time configuration, you just tell nginx to run localhost:your-port as the upstream and export shell variables:

  $ export MONGO_URL='mongodb://user:password@host:port/databasename'
  $ export ROOT_URL='http://example.com'
  $ export MAIL_URL='smtp://user:password@mailhost:port/'

Enjoy and never pay for free software that was given to us by GNUGPL again.

1 Like