NPM-使用PM2来运行应用的NPM问题

时间:2019-03-06 10:38:39

标签: node.js npm pm2

我正在关注ReactJS课程的应用程序。一切都很好。当我在数字npm run production上运行应用程序的后端时,它已成功编译。突然停止工作了。外壳中出现了一条错误消息(打印屏幕):

enter image description here

这是我的文件:

loader.js

const server = require('./config/server')
require('./config/database')
require('./config/routes')(server)

server.js

const port = 3030
const bodyParser = require('body-parser') 
const express = require('express')
const server = express()
const allowCors = require('./cors') 
const queryParser = require('express-query-int')

server.use(bodyParser.urlencoded({ extended: true }))
server.use(bodyParser.json())
server.use(allowCors)
server.use(queryParser())

server.listen(port, function(){
  console.log(`BACKEND is runing on port ${port}.`)
})

module.exports = server;

router.js

const express = require('express')

module.exports = function(server){ 
  const router = express.Router()
  server.use('/api', router)

  const BillingCycle = require('../api/billingCycle/billingCycleService')
  BillingCycle.register(router, '/billingCycles')
}

database.js

const mongoose = require('mongoose')

mongoose.Promise = global.Promise
module.exports = mongoose.connect('mongodb://localhost/mymoney')

mongoose.Error.messages.general.required = "O tributo '{PATH}' é obrigatório."
mongoose.Error.messages.Number.min =
"O '{VALUE}' informado é menor que o limite mínimo de '{MIN}'."
mongoose.Error.messages.Number.max =
"O '{VALUE}' informado é maior que o limite máximo de '{MAX}'."
mongoose.Error.messages.String.enum = 
"'{VALUE}' não é válido para o atributo '{PATH}'."

cors.js

module.exports = (req, res, next) => {
  res.header('Access-Control-Allow-Orign', '*')
  res.header('Access-Control-Allow-Orign', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
  res.header('Access-Control-Allow-Orign', 'Origin, X-Requested-With, Content-type, Accept')
  next()
}  

package.json

 {   "name": "backend",   "version": "1.0.0",   "description": "",  
 "main": "src/loader.js",   "scripts": {
     "dev": "nodemon",
     "production": "pm2 start src/loader.js --name my-money-backend"   },   "keywords": [],   "author": "",   "license": "ISC",  
 "dependencies": {
     "body-parser": "^1.15.2",
     "eslint-cli": "^1.1.1",
     "express": "^4.14.0",
     "express-query-int": "^3.0.0",
     "lodash": "^4.17.4",
     "mongoose": "^4.7.0",
     "mongoose-paginate": "^5.0.3",
     "node-restful": "^0.2.5",
     "pm2": "^3.3.1"   },   "devDependencies": {
     "nodemon": "^1.11.0"   } }

0 个答案:

没有答案