Hosting Meteor 1.5 app on Local Windows Server

Hello,
I have been trying to follow various posts on deploying meteor to windows but unfortunately I have not been able to successfully do this.
I am trying to deploy a meteor 1.5 application and so far I have been able ;

  • to generate the build successfully.
  • I cd programs/server && run npm install ( I got a few warning and these errors

'node-pre-gyp' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! bcrypt@1.0.2 install:node-pre-gyp install --fallback-to-buildnpm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bcrypt@1.0.2 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! meteor-dev-bundle@0.0.0 install:node npm-rebuild.jsnpm ERR! Exit status 1 npm ERR! npm ERR! Failed at the meteor-dev-bundle@0.0.0 install script.

I ignored these and went on to cd into bundle and run node main.js and I got the following

`Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run

meteor npm install --save bcrypt

in the root directory of your application.
C:\ARBProd\bundle\programs\server\node_modules\fibers\future.js:280
throw(ex);
^

Error: MONGO_URL must be set in environment
at Object. (packages/mongo/remote_collection_driver.js:36:11)
at Object.defaultRemoteCollectionDriver (packages\underscore.js:784:19)
at new Mongo.Collection (packages/mongo/collection.js:99:40)
at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)
at meteorInstall.node_modules.meteor.accounts-base.server_main.js (packages/accounts-base/server_main.js:9:12)
at fileEvaluate (packages\modules-runtime.js:197:9)
at require (packages\modules-runtime.js:120:16)
at C:\ARBProd\bundle\programs\server\packages\accounts-base.js:2019:15
at C:\ARBProd\bundle\programs\server\packages\accounts-base.js:2030:3`

Please help. I am assuming the last error requires me to install mongo and somehow set the url etc. I have always run mongo only from meteor and not sure how to go about all that. Please help, i really need to get the app running on production server now.

NB: all I have done so far is still on my development environment (windows 10 64bit)

@rafaelfaria @reecestart @jesalr @system @discobot @floydprice @allenfuller @brucejo @babrahams @robfallows @jamgold @ffxsam @msavin @abernix @herteby @vigorwebsolutions @fullhdpixel @hwillson @waldgeist @hexsprite @mnmtanish @ralpheiligan @mysterymac @SkyRooms @hoser23331

i could be wrong about this but i don’t think you can use the mongo database shipped with meteor in production. so either you set up mongodb on your server and set MONGO_URL to localhost or use a service like compose.
i highly recommend the second option.
though i’d also recommend using galaxy or mup with a linux server for hosting the application.
the hassle of running all of this yourself just doesn’t pay off - i’ve been there ^^

@chris74656 thanks for replying. Unfortunately, I have to host locally. its a requirement i cannot change.
Do you have some steps on how to setup mongo locally and set the mongo_url?
It will really help me.

Thanks

sorry, i’ve never tried to run a production build on windows. at least for dev you can just put set MONGO_URL=mongodb://127.0.0.1 into cmd before meteor run to connect to a database other than meteor’s own.

for mongo itself - their docs are quite well done https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/

Progress!
I have been able to install a standalone version of mongo 3.2 and also setup up a windows service for it.
I have also tried to uninstall and install bcrypt as suggested here, to get rid of the first part of the error,

Note: you are using a pure-JavaScript implementation of bcrypt. While this implementation will work correctly, it is known to be approximately three times slower than the native implementation. In order to use the native implementation instead, run meteor npm install --save bcrypt

but that message still exists.

I have also created a windows enrvironment variable MONGO_URL to mongodb://localhost:27017/ARB.

`C:\ARBProd\bundle\programs\server\node_modules\fibers\future.js:280
throw(ex);
^

Error: Must pass options.rootUrl or set ROOT_URL in the server environment
at Object.Meteor.absoluteUrl (packages\meteor.js:1268:11)
at email_templates.js (packages/accounts-password/email_templates.js:23:20)
at fileEvaluate (packages\modules-runtime.js:197:9)
at require (packages\modules-runtime.js:120:16)
at C:\ARBProd\bundle\programs\server\packages\accounts-password.js:1139:1
at C:\ARBProd\bundle\programs\server\packages\accounts-password.js:1146:3
at C:\ARBProd\bundle\programs\server\boot.js:303:34
at Array.forEach (native)
at Function..each..forEach (C:\ARBProd\bundle\programs\server\node_modules\underscore\underscore.js:79:11)
at C:\ARBProd\bundle\programs\server\boot.js:128:5
PS C:\ARBProd\bundle>`

  • The challenge now is to set ROOT_URL or pass it.
  • Also this new environment variable now affect other meteor applications. The intention was to get only this production ready app to work. How do I resolve that?

@chris74656 Thanks for replying

I regularly deploy Meteor on Windows for exclusively local use (Kiosk mode installations).
What we do is we have a .bat file to start the build with the appropriate variables like so:

cd C:\Users\%USERNAME%\project-name\scripts\
set /p METEOR_SETTINGS=<settings-build.json

cd C:\Users\%USERNAME%\project-name\build\
set ROOT_URL=http://localhost:3000
set PORT=3000
set MONGO_URL=mongodb://localhost:27017/project-name

node main.js

As for your pre-gyp issue, that looks like you don’t have the build tools required to compile c++/native node extensions (like bcrypt). To get them, open an administrator command prompt and run:

npm install --global windows-build-tools

It takes a while to install, so you’ll need to be patient

And if you haven’t already, have a good read of the custom deployment section of the Meteor Guide:

1 Like

@coagmano.

Thank you so much, you are just about to save me big time.

  1. Please where do I put this .bat file? also are you saying all of this below is in the .bat file?

`cd C:\Users%USERNAME%\project-name\scripts
set /p METEOR_SETTINGS=<settings-build.json

cd C:\Users%USERNAME%\project-name\build
set ROOT_URL=http://localhost:3000
set PORT=3000
set MONGO_URL=mongodb://localhost:27017/project-name

node main.js`

  1. On As for your pre-gyp issue, that looks like you don’t have the build tools required to compile c++/native node extensions (like bcrypt). To get them, open an administrator command prompt and run: I am actually running the production build on my current development machine first so that f all works, then I move to the actual production app. So I am surprised why the current machine will not have build tools as I have used it to run several meteor projects ( though all as development) and this is my first attempt at deployment.

  2. On reading the meteor custome deploy again, I see they have MONGO_URL=mongodb://localhost:27017/myapp ROOT_URL=http://my-app.com node main.js
    how can i make this into a service or something so that when the production server is started, this script is run automomatically?

  3. I have tried to run MONGO_URL=mongodb://localhost:27017/ARB ROOT_URL=localhost:3000 node main.js but I get

`MONGO_URL=mongodb://localhost:27017/ARB : The term ‘MONGO_URL=mongodb://localhost:27017/ARB’ is not recognized as the
name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1

  • MONGO_URL=mongodb://localhost:27017/ARB
  • + CategoryInfo          : ObjectNotFound: (MONGO_URL=mongodb://localhost:27017/ARB:String) [], >CommandNotFoundExce
    

ption

  • FullyQualifiedErrorId : CommandNotFoundException`

Thank you for your help

I think developing on a Mac OS and deploying to a Unix-based server is going to make your life a lot easier. Modern web dev is already complicated enough. I think trying to do Meteo/Node on Windows is just begging to additional headache.

Autostart

For autostart we simply configured Windows to automatically log in the user and then stuck a shortcut to the bat in the startup folder (in the start menu). If that doesn’t work for you, you’ll need to go googling how to run a bat file or node with custom env vars as a service.

.bat file

Let me break down what the bat file does:

cd C:\Users%USERNAME%\project-name\scripts
  1. Change the working directory to the folder with the scripts
set /p METEOR_SETTINGS=<settings-build.json
  1. Load settings-build.json into the METEOR_SETTINGS environment variable
    • Equivalent of meteor --settings settings-build.json
    • Note cmd doesn’t like line breaks, so minify the json before deploy
cd C:\Users%USERNAME%\project-name\build
  1. Change the working directory to the build folder (usually called bundle)
set ROOT_URL=http://localhost:3000
set PORT=3000
set MONGO_URL=mongodb://localhost:27017/project-name
  1. Set the other environment variables in the Windows way
    • As you found setting them in the one line like the docs suggest is the *nix way and won’t work on Windows
node main.js
  1. Start the built app

Obviously you’ll need to change the dirs and vars to what you need.

windows-build-tools

Unless you have already done development which requires compilations of native addons, you won’t necessarily already have these as most npm packages are pure javascript. I strongly recommend installing this package on any machine you will run npm install so you don’t end up with failures when you finally need it.

Installing a build of meteor is always one of the cases where you need it. (The install script in programs/server will always trigger a rebuild of native addons because Meteor uses Fibers)

1 Like

@coagmano It worked!!!

I am still getting warnings for bcrypt, but it actually worked.
I had to edit the .bat a bit and currently running it by double clicking.
I actually didn’t know it was working as nothing was showing on the console. I just tried to open the address, and it was working!!!
Thank you so much @coagmano.

I am now investigating running the .bat with NSSM. Also working on auth for the mongo.

  1. Is there a way to make the .bat ensure mongo is up and running before it continues to start the Node server?
  2. Is there a way to call a browser with the address automatically once the service successfully starts, so that a user knows the app is running?
    I will update if i find answers for others who may need it.

Thank you again.

I start mongo with another .bat file that just points to the executable

# mongod.bat
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"

And start chrome in a bat file!

# startChrome.bat
start chrome --incognito --kiosk http://localhost:3000

put it all together and you have the one startup file:

# run.bat
cd C:\Users\%USERNAME%\project-name\scripts

start /b mongod.bat
TIMEOUT /T 5
start /b microservices.bat
TIMEOUT /T 5
start runbuild.bat # This is the bat file in my first comment

TIMEOUT /T 5

start startChrome.bat

The timeouts are useful to make sure dependent services / node is running before the next process / chrome starts

1 Like

@coagmano I am very grateful!

If you start your Mongodb as a window service, it will already be running before your app starts.
I have been running like this for 2 years now without problem

1 Like