This is a simple example of how to deploy a Nodejs app to Meteor Cloud. It's a bit of a hack, but it works.
- Create a meteor app using
meteor create --bare myapp
- Add the file
server/main.js
to your app - this is the entry point for your app - Add the following configuration to your
package.json
:
"meteor": {
"mainModule": {
"server": "server/main.js"
}
}
- You need to use the following configuration with
WebApp
:
import { WebApp } from 'meteor/webapp'
// your app code here
WebApp.connectHandlers.use(fastify.server)
- You can now add your Nodejs code to
server/main.js
. In this example, I'm using Fastify, but feel free to use other solutions, like Express. - Deploy your app to Meteor Cloud using the CLI or the web interface.
Just be aware that Meteor by default will be listening to port 3000, so you'll need to listen to a different port in your Nodejs app.
import Fastify from 'fastify'
import { WebApp } from 'meteor/webapp'
const fastify = Fastify({
logger: false,
})
fastify.get('/', (request, reply) => {
reply.send({ message: 'This is a Fastify app deployed to Meteor Cloud' })
})
fastify.listen({ port: 4000 }, (err, address) => {
if (err) throw err
console.log(`server listening on ${address}`)
})
WebApp.connectHandlers.use(fastify.server)