Heroku部署 - 同时运行两个脚本?

时间:2016-12-17 02:17:30

标签: javascript mongodb reactjs heroku web-deployment

我已经构建了一个使用React和Mongo的完整堆栈应用程序。基本上在我的package.json中,我有这个脚本:

  "scripts": {
    "start": "node server.js & node src/server/index.js ",
  },

其中server.js是使用webpack保存前端的地方,而t src/server/index.js是React从中获取数据的API数据库。

我已经尝试过部署,但由于脚本我收到了错误。

我已经部署了每个(一次一个)并且两者都有效。

有没有办法告诉Heroku同时运行两个脚本?

对于那些好奇的人来说,这是我的package.json

的package.json

{
  "name": "fcc-vote-app",
  "version": "1.0.0",
  "description": "demo",
  "main": "index.js",
  "repository": "",
  "scripts": {
    "start": "node  src/server/index.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --require ignore-styles  --recursive ./test",
    "test:watch": "npm run test -- --watch",
    "dev": "nodemon src/server/index.js "
  },
  "author": "Kenzo Mendoza",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "express": "^4.13.4",
    "ignore-styles": "^5.0.1",
    "jquery": "^3.1.1",
    "jsdom": "^9.8.3",
    "mocha": "^3.2.0",
    "node-sass": "^4.0.0",
    "react-addons-test-utils": "^15.4.1",
    "react-hot-loader": "3.0.0-beta.2",
    "webpack": "^1.14.0",
    "webpack-dev-middleware": "^1.6.1",
    "webpack-dev-server": "^1.16.2",
    "webpack-hot-middleware": "^2.10.0"
  },
  "dependencies": {
    "axios": "^0.15.3",
    "babel-preset-stage-1": "^6.1.18",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.15.2",
    "chart.js": "^1.1.1",
    "chartjs-color": "^2.0.0",
    "cors": "^2.8.1",
    "css-loader": "^0.26.1",
    "express": "^4.14.0",
    "jwt-simple": "^0.5.1",
    "lodash": "^4.17.2",
    "moment": "^2.17.1",
    "mongoose": "^4.7.1",
    "morgan": "^1.7.0",
    "node-sass": "^3.13.0",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1",
    "passport-local": "^1.0.0",
    "proxy-middleware": "^0.15.0",
    "react": "^15.4.1",
    "react-chartjs": "^0.8.0",
    "react-dom": "^15.4.1",
    "react-materialize": "^0.17.6",
    "react-redux": "^5.0.1",
    "react-router": "^3.0.0",
    "react-thunk": "^1.0.0",
    "redux": "^3.0.4",
    "redux-form": "^6.2.1",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.1.0",
    "sass-loader": "^4.0.2",
    "style-loader": "^0.13.1",
    "write-file-webpack-plugin": "^3.4.2"
  }
}

webpack.config.js

var path = require('path')
var webpack = require('webpack');
var WriteFilePlugin = require('write-file-webpack-plugin');
module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './src/client/index.js'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      test: /\.js$/,
      loaders: ['babel-loader'],
      include: path.join(__dirname, 'src')
    },{
      test: /\.s?css$/,
      loaders: ['style','css','sass'],
      include: path.join(__dirname, 'src')
    }]
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({minimize: true}),
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': JSON.stringify("production")
      }
    }),
    new WriteFilePlugin()
  ],
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  devServer: {
    historyApiFallback: true,
    contentBase: './',
    outputPath: path.join(__dirname, './dist')
  }
};

编辑:

当我尝试同时执行这两项操作时,我的heroku日志中出现以下错误:

2016-12-17T14:09:37.270490+00:00 app[web.1]: Error: listen EADDRINUSE :::6262
2016-12-17T14:09:37.270491+00:00 app[web.1]:     at Object.exports._errnoException (util.js:1026:11)
2016-12-17T14:09:37.270491+00:00 app[web.1]:     at exports._exceptionWithHostPort (util.js:1049:20)
2016-12-17T14:09:37.270492+00:00 app[web.1]:     at Server._listen2 (net.js:1257:14)
2016-12-17T14:09:37.270497+00:00 app[web.1]:     at listen (net.js:1293:10)
2016-12-17T14:09:37.270498+00:00 app[web.1]:     at Server.listen (net.js:1389:5)
2016-12-17T14:09:37.270499+00:00 app[web.1]:     at EventEmitter.listen (/app/node_modules/express/lib/application.js:617:24)
2016-12-17T14:09:37.270500+00:00 app[web.1]:     at Object.<anonymous> (/app/src/server/index.js:28:5)
2016-12-17T14:09:37.270501+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2016-12-17T14:09:37.270501+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2016-12-17T14:09:37.270502+00:00 app[web.1]:     at Module.load (module.js:487:32)
2016-12-17T14:09:37.270502+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2016-12-17T14:09:37.270503+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2016-12-17T14:09:37.270504+00:00 app[web.1]:     at run (bootstrap_node.js:394:7)
2016-12-17T14:09:37.270503+00:00 app[web.1]:     at Module.runMain (module.js:604:10)
2016-12-17T14:09:37.270505+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2016-12-17T14:09:37.270505+00:00 app[web.1]:     at bootstrap_node.js:509:3
2016-12-17T14:09:37.279482+00:00 app[web.1]: 
2016-12-17T14:09:37.286816+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic
2016-12-17T14:09:37.287012+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-12-17T14:09:37.287289+00:00 app[web.1]: npm ERR! node v6.9.1
2016-12-17T14:09:37.287435+00:00 app[web.1]: npm ERR! npm  v3.10.8
2016-12-17T14:09:37.287692+00:00 app[web.1]: npm ERR! fcc-vote-app@1.0.0 start: `node server.js & node src/server/index.js `
2016-12-17T14:09:37.287571+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-12-17T14:09:37.287843+00:00 app[web.1]: npm ERR! Exit status 1
2016-12-17T14:09:37.288022+00:00 app[web.1]: npm ERR! 
2016-12-17T14:09:37.288196+00:00 app[web.1]: npm ERR! Failed at the fcc-vote-app@1.0.0 start script 'node server.js & node src/server/index.js '.
2016-12-17T14:09:37.288316+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-12-17T14:09:37.288424+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the fcc-vote-app package,
2016-12-17T14:09:37.288528+00:00 app[web.1]: npm ERR! not with npm itself.
2016-12-17T14:09:37.288676+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-12-17T14:09:37.288790+00:00 app[web.1]: npm ERR!     node server.js & node src/server/index.js 
2016-12-17T14:09:37.288895+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-12-17T14:09:37.289002+00:00 app[web.1]: npm ERR!     npm bugs fcc-vote-app
2016-12-17T14:09:37.289109+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-12-17T14:09:37.289215+00:00 app[web.1]: npm ERR!     npm owner ls fcc-vote-app
2016-12-17T14:09:37.289323+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-12-17T14:09:37.293918+00:00 app[web.1]: 
2016-12-17T14:09:37.294152+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-12-17T14:09:37.294295+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-12-17T14:09:37.389806+00:00 heroku[web.1]: State changed from up to crashed
2016-12-17T14:09:37.389806+00:00 heroku[web.1]: State changed from crashed to starting
2016-12-17T14:09:37.374650+00:00 heroku[web.1]: Process exited with status 1
2016-12-17T14:09:41.235414+00:00 heroku[web.1]: Starting process with command `npm start`
2016-12-17T14:09:44.912422+00:00 app[web.1]: 
2016-12-17T14:09:44.912434+00:00 app[web.1]: > fcc-vote-app@1.0.0 start /app
2016-12-17T14:09:44.912435+00:00 app[web.1]: > node server.js & node src/server/index.js 
2016-12-17T14:09:44.912435+00:00 app[web.1]: 
2016-12-17T14:09:45.500459+00:00 app[web.1]: [14:09:45] [write-file-webpack-plugin] options { exitOnErrors: true,
2016-12-17T14:09:45.500472+00:00 app[web.1]:   force: false,
2016-12-17T14:09:45.500473+00:00 app[web.1]:   log: true,
2016-12-17T14:09:45.500474+00:00 app[web.1]:   test: null,
2016-12-17T14:09:45.500475+00:00 app[web.1]:   useHashIndex: true }
2016-12-17T14:09:45.586438+00:00 app[web.1]: Clien is Listening port at 6629
2016-12-17T14:09:45.724941+00:00 app[web.1]: events.js:160
2016-12-17T14:09:45.724944+00:00 app[web.1]:       throw er; // Unhandled 'error' event
2016-12-17T14:09:45.724945+00:00 app[web.1]:       ^
2016-12-17T14:09:45.724945+00:00 app[web.1]: 
2016-12-17T14:09:45.724946+00:00 app[web.1]: Error: listen EADDRINUSE :::6629
2016-12-17T14:09:45.724947+00:00 app[web.1]:     at Object.exports._errnoException (util.js:1026:11)
2016-12-17T14:09:45.724948+00:00 app[web.1]:     at exports._exceptionWithHostPort (util.js:1049:20)
2016-12-17T14:09:45.724948+00:00 app[web.1]:     at Server._listen2 (net.js:1257:14)
2016-12-17T14:09:45.724949+00:00 app[web.1]:     at listen (net.js:1293:10)
2016-12-17T14:09:45.724950+00:00 app[web.1]:     at Server.listen (net.js:1389:5)
2016-12-17T14:09:45.724951+00:00 app[web.1]:     at EventEmitter.listen (/app/node_modules/express/lib/application.js:617:24)
2016-12-17T14:09:45.724951+00:00 app[web.1]:     at Object.<anonymous> (/app/src/server/index.js:28:5)
2016-12-17T14:09:45.724952+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2016-12-17T14:09:45.724953+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2016-12-17T14:09:45.724953+00:00 app[web.1]:     at Module.load (module.js:487:32)
2016-12-17T14:09:45.724954+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2016-12-17T14:09:45.724955+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2016-12-17T14:09:45.724955+00:00 app[web.1]:     at Module.runMain (module.js:604:10)
2016-12-17T14:09:45.724956+00:00 app[web.1]:     at run (bootstrap_node.js:394:7)
2016-12-17T14:09:45.724957+00:00 app[web.1]:     at startup (bootstrap_node.js:149:9)
2016-12-17T14:09:45.724957+00:00 app[web.1]:     at bootstrap_node.js:509:3
2016-12-17T14:09:45.739572+00:00 app[web.1]: 
2016-12-17T14:09:45.751015+00:00 app[web.1]: npm ERR! Linux 3.13.0-105-generic
2016-12-17T14:09:45.751377+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-12-17T14:09:45.751619+00:00 app[web.1]: npm ERR! node v6.9.1
2016-12-17T14:09:45.751818+00:00 app[web.1]: npm ERR! npm  v3.10.8
2016-12-17T14:09:45.752024+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2016-12-17T14:09:45.752210+00:00 app[web.1]: npm ERR! fcc-vote-app@1.0.0 start: `node server.js & node src/server/index.js `
2016-12-17T14:09:45.752360+00:00 app[web.1]: npm ERR! Exit status 1
2016-12-17T14:09:45.752529+00:00 app[web.1]: npm ERR! 
2016-12-17T14:09:45.752690+00:00 app[web.1]: npm ERR! Failed at the fcc-vote-app@1.0.0 start script 'node server.js & node src/server/index.js '.
2016-12-17T14:09:45.752836+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2016-12-17T14:09:45.752994+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the fcc-vote-app package,
2016-12-17T14:09:45.753145+00:00 app[web.1]: npm ERR! not with npm itself.
2016-12-17T14:09:45.753307+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2016-12-17T14:09:45.753636+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2016-12-17T14:09:45.753486+00:00 app[web.1]: npm ERR!     node server.js & node src/server/index.js 
2016-12-17T14:09:45.753827+00:00 app[web.1]: npm ERR!     npm bugs fcc-vote-app
2016-12-17T14:09:45.754017+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2016-12-17T14:09:45.754188+00:00 app[web.1]: npm ERR!     npm owner ls fcc-vote-app
2016-12-17T14:09:45.754380+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-12-17T14:09:45.759638+00:00 app[web.1]: 
2016-12-17T14:09:45.759913+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-12-17T14:09:45.760061+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-12-17T14:09:45.836685+00:00 heroku[web.1]: Process exited with status 1
2016-12-17T14:09:45.850316+00:00 heroku[web.1]: State changed from starting to crashed
2016-12-17T14:09:47.236985+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=votez-app.herokuapp.com request_id=370513f4-7002-4269-9410-78f5e70ca467 fwd="108.207.136.140" dyno= connect= service= status=503 bytes=

1 个答案:

答案 0 :(得分:0)

这可能是因为PORT冲突,Heroku在单个PORT上运行“node server.js & node src/server/index.js”。