项目作者: azizijunaid

项目描述 :
Restfull Api's build on nodejs mysql
高级语言: JavaScript
项目地址: git://github.com/azizijunaid/NodeJsMySql.git
创建时间: 2020-06-24T23:12:20Z
项目社区:https://github.com/azizijunaid/NodeJsMySql

开源协议:MIT License

下载


Docker

You will need docker and docker-compose installed to build the application.

After installing docker, start the application with the following commands :

  1. # To build the project for the first time or when you add dependencies
  2. docker-compose build web
  3. # To start the application (or to restart after making changes to the source code)
  4. docker-compose up web

To view the app, find your docker IP address + port 8080 ( this will typically be http://localhost:8080/ ). To use a port other than 8080, you would need to modify the port in app.js, Dockerfile, and docker-compose.yml.


Add these two lines to app.js, just place them anywhere before app.listen():

  1. var IP_ADDRESS = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
  2. var PORT = process.env.OPENSHIFT_NODEJS_PORT || 8080;

Then change app.listen() to:

  1. app.listen(PORT, IP_ADDRESS, () => {
  2. console.log(
  3. `Express server listening on port ${PORT} in ${app.settings.env} mode`
  4. );
  5. });

Add this to package.json, after name and version. This is necessary because, by default, OpenShift looks for server.js file. And by specifying supervisor app.js it will automatically restart the server when node.js process crashes.

  1. "main": "app.js",
  2. "scripts": {
  3. "start": "supervisor app.js"
  4. },