How to run parse server with own configure?

#1

Hello.
Before I used parse-server-example .
Now I installed just parse-server.

And in parse-server-example we have index.js file to write configure parse server and then run it.

How to do same file in just parse-server?

#2

You can check our sample repo.
Hope this will help you :slight_smile:

#3

Hi @jaswgo

There’s a bunch of different way to pass config to a parse server. Here’s how I do it!

  1. This is the script section of my package.json:
"scripts": {
    "test": "NODE_ENV=test jasmine",
    "start": "parse-server ./config.js",
    "pretest": "MONGODB_VERSION=3.6.5  mongodb-runner start --port=27117",
    "posttest": "mongodb-runner stop"
  },

note that the start key invokes parse-server and passes it the location of my config file.

Here’s my the entire contents of the config file in the root of my parse-server directory (same location as the package.json file)

const config = require('config');
module.exports = config.parseServerOptions;

Which includes the excellent config package

I have a directory ./config that has the files default.js, test.js, development.js, production.js & local.js files (local.js is gitignored).

As the documentation for config indicates, I use an environment variable NODE_ENV to tell config how to load and merge the config files. So when I’m working on my local box where there is no NODE_ENV set, default.js will be loaded first and then merged with local.js.

In my config/*.js files, looks something like this…

module.exports = {
  secretBoxKey: ...,
  cloudFrontSigner: new AWS.CloudFront.Signer(...)),
  stripe: {
     ....
  },
  algolia: {
    ....
  },
  parseServerOptions: {
    cluster: true,
    appId: ...,
    masterKey: ...,
    databaseURI: 'mongodb://...',
    verbose: false,
....

note the parseServerOptions section is what gets exported in the ./config.js files that gets passed to the parse-server command when I run npm start to start my server.

Good luck!