Search code examples
node.jsmongodbgoogle-app-enginegoogle-compute-enginekeystonejs

KeystoneJS app failing to deploy on Google App Engine


I have a KeystoneJS app on a Google Compute Engine instance, after executing mongod and npm start in my project folder, I run gcloud app deploy and get the following error:

Mongoose connection "error" event fired with:
{ MongoError: failed to connect to server [localhost:27017] on first connect
at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:326:35)
at Pool.emit (events.js:182:13)
at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:272:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:175:49)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
name: 'MongoError',
message:
'failed to connect to server [localhost:27017] on first connect' }
Error: KeystoneJS (Modern Marketing) failed to start - Check that you are running `mongod` in a separate process.
at NativeConnection.<anonymous> (/app/node_modules/keystone/lib/core/openDatabaseConnection.js:59:10)
at NativeConnection.emit (events.js:182:13)
at Immediate.<anonymous> (/app/node_modules/mongoose/lib/connection.js:296:19)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node keystone.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-01-02T05_59_39_493Z-debug.log

I don't have much experience with MongoDB or KeystoneJS, so any insight is appreciated


Solution

  • It seems that while deploying to GAE, you're keeping the default connection to a local hosted mongo database. (failed to connect to server [localhost:27017])

    Since GAE environment doesn't have mongodb running, you have to create a mongo database (there are many different mongodb services that you could use here) and set your project up with MONGO_URI env variable.

    Keystonejs will then try to connect the database you set in this variable.

    I hope this comment will help you, if you still have some issues setting all that stuff up, you can show us your app.yaml file ;)