The API backend for Verpix.
Install dependent npm modules:
$ npm install
Install dependent tools:
$ npm install pm2 -g
Install Gearman.
- Install Gearman on Mac
-
Build image
$ docker build -t laputa-api ./
-
Create container
$ docker create -p 3000:3000 --restart always $imageId
-
Start container
$ docker start $containerId
Set up a Gearman job server before starting the server.
HOST
The hostname of the server (default: '0.0.0.0')PORT
The port number that the server is serving (default: 3000)NODE_ENV
The environment mode (dev/production) that the server is runningDB_URL
The URL to connect to MongoDB service (default in Dev mode: 'mongodb://localhost:27017/verpix-dev-db', no default setting for Production mode)S3_BKT
The bucket name of the AWS S3 service (no default setting)G_SERVERS
The server list of the gearman job servers (default: [ { host: 'localhost', port: 4370 } ])
You need to setup a MongoDB service for server to running in this mode. The default MongoDB setting for the server is 'mongodb://localhost:27017/verpix-dev-db'. To change the default setting, use the environment variable: DB_URL
.
$ npm run dev
$ DB_URL='mongodb://192.0.0.1:27019/verpix-dev-db2' npm run dev
$ S3_BKT='verpix-dev-bucket-2' npm run dev
You can access the API documentation in this mode at http://localhost:3000
.
The server will be running in background and monitoring by pm2 in this mode. It's also need MongoDB as a dependent service, and there is no default setting for MongoDB and S3 in this mode.
$ DB_URL='mongodb://localhost:27017/verpix-dev-db' S3_BKT='verpix-img-production' G_SERVERS='[{"host": "localhost", "port": 4370}]' npm start
By default, npm start
will set env variable NODE_ENV
to production so you don't have to set it manually.
$ pm2 show verpix-api
$ pm2 status
$ npm stop
$ npm test