-->

Deploy Meteor on Windows

2019-03-13 11:44发布

问题:

I find it rather weird that there are no detailed step by step explanations on how to deploy your own Meteor webapp onto your own Windows server. Or maybe I'm just not able to use Google to find one such explanation.

On many pages, even on some questions here on SO, I found people simply saying "build it and deploy it like any other node.js app" which is great, except I can't find any explanation on how to deploy a node.js webapp on to a Windows server either.

Meteor is so awesome, that I feel if anyone would write up such a step by step on how to deploy a Meteor app on a Windows server, a looooot of people would be very happy campers... Especially if the explaintion describes how to deploy multiple Meteor apps onto one Windows server ;)

It certainly does not have to be IIS, nginx runs on Windows just fine.

Also, Node.js runs on Windows just fine. MongoDB runs on Windows just fine, as a service. Meteor builds the apps on Windows apparently just fine. So, it really is missing just one last step to get it deployed on a Windows server as well...

So, anyone out there knows how to deploy several Meteor apps on one Windows server and is willing to write up a n00b-friendly step by step explanation for that?

Pretty please?

回答1:

Predrag -- I started to write up what I hope is going to be a fairly reasonable step-by-step guide on the Meteor Forums here: Windows Deployment.

Hopefully over the next few days I'll complete it, but it's a start!

Meanwhile here are the basic steps for those who don't need a step-by-step guide:

  • On some Windows machine (can certainly be your development machine if you are developing on Windows) make sure to have the following installed:

    1. Meteor
    2. VS12 (VS15 maybe able to work, but I am using VS12) with the c++ command line build tools installed!
    3. Node (if you are tricky can be the same node as is embedded in Meteor) otherwise any node should work
    4. npm
    5. demeteorizer (npm install -g demeteorizer)
  • Then from your Meteor project run the following:

    demeteorizer -o c:\somepath
    cd c:\somepath\bundle\programs\server
    npm install
    

This is the critical part. The last command will attempt to build Fibers .. so make sure the VS command line tools can be found and work.

If the above works, you are almost home!

Running To run the application -- it IS very similar to any other node application except we need to define (at a minimum) two environment variables (the first two below). I do this via a .bat file, but whatever equivalent should be able to work. The ENV variables are defined in the README file under the bundle directory above BTW if you want to read about them.

set MONGO_URL=mongodb://localhost:27017/mydbname
set ROOT_URL=http://myapp.example.com:8080
set PORT=8080
set MAIL_URL=smtp://user:password@host:port
node main.js

Now the above assumes many simplistic things, namely that your are running your MongoDB on the local machine, with no user security, at the default port. If not, you'll need to change the MONGO_URL part to reflect reality. The "mydbname" is whatever logical name you want to call your collection of documents. In Development mode this was "meteor" but it's unlikely that makes much sense in production (especially if it's against a real production DB!). This also assumes NO Oplog Tailing.

I like to specify the PORT explicitly in the .bat file so it's clear and of course needs to be done unless you want to use 3000 (or 80 - whatever the default is, which I don't remember).

You may also have to set the MAIL_URL if you are using any of the user packages that does email notification, etc. I put it above but it's optional.

Anyway, that's the basics. For more details please read the guide linked above (which is a work in progress).



回答2:

Well, their page about custom deployment is quite short and I discovered some facts while managing to deploy the Welcome to Meteor application:

  • the ROOT_URL environment variable is required but seems that the port number inside makes no sense.
  • the port number is defined by the PORT environment variable or assigned by node. This PORT variable is not mentioned in the guide. I used the netstat command to find out the port used.
  • the MONGO_URL environment variable is optional in this application.
  • must run npm install before executing the meteor build

Hope this help.