How to run built of Meteor's sample app via No

2019-09-14 04:18发布

问题:

I want to run the most basic Meteor app via Node. I make the following, orderly;

  1. mkdir src && cd src
  2. meteor create sample_app
  3. npm install --production
  4. meteor build … --allow-superuser --directory
  5. cd …/bundle
  6. node --version

    v4.6.1

  7. node main.js

But, it throws the following error;

module.js:327
throw err;
^

*Error: Cannot find module 'fibers’
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object. 

(/server/boot.js:1:75)

at Module._compile (module.js:409:26)
at Object.Module._extensions…js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)*

Why cannot I run the most basic Node app via those simple steps? Thank you!

回答1:

This may have something to do with the new architecture of the meteor bundle (the process which converts a Meteor app to a regular Node.js app).

In Meteor < 0.9 you had to run npm install at the root of the bundle to get npm modules installed, now you have to cd in programs/server first, as stated in the README :

This is a Meteor application bundle. It has only one external dependency:
Node.js 0.10.29 or newer. To run the application:

  $ (cd programs/server && npm install)
  $ export MONGO_URL='mongodb://user:password@host:port/databasename'
  $ export ROOT_URL='http://example.com'
  $ export MAIL_URL='smtp://user:password@mailhost:port/'
  $ node main.js

Use the PORT environment variable to set the port where the
application will listen. The default is 80, but that will require
root on most systems.

Find out more about Meteor at meteor.com.

Modulus developed a tool called demeteorizer which is supposed to automate this process of converting a Meteor app to a Node.js app, and it's possible that they have not yet modified the tool to account for 0.9 changes.



回答2:

You simply need to

npm install

and possibly export environment variables first, depending on what you need in your application.

export MONGO_URL='mongodb:'mongodb://user:password@host:port/databasename'
...

After that you just run the bundled app with node

node main.js


回答3:

I assume you have installed node js, pm2, mongodb and you have create a DBNAME, USER with USERNAME and PASSWORD.

After you create a meteor project.

  1. BUILD using command meteor build --server-only .
  2. A tar file xyz.tar.gz will be created for you. Use command tar -xzf xyz.tar.gz to untar it.
  3. Inside the folder goto bundle/programs/server/ and then run command npm install --production
  4. Install pm2 node package.
  5. set mongo db properties as export MONGO_URL=”mongodb://username:password@127.0.0.1:27017/dbName”;export ROOT_URL=”http://localhost/”;export PORT=3000
  6. Go back to bundle/ directory and run pm2 using command pm2 start --name “UID” main.js.
  7. To view if project is online and running use command pm2 show 0