I created an ecosystem.json
```
{
"apps": [{
"name": "question_system",
"script": "./bin/www",
"env":{
"COMMON_VARIABLE": "true"
},
"env_production": {
"NODE_ENV": "production"
}
}],
"deploy": {
"production": {
"user": "wusong",
"host": ["39.108.55.141"],
"ref": "origin/master",
"repo": "git@github.com:WUSO01/nodejs-question-system.git",
"path": "/home/wusong/www/question/production",
"ssh_options": "StrictHostKeyChecking=no",
"post-deploy": "npm install && pm2 startOrRestart ecosystem.json --env production",
"env": {
"NODE_ENV": "production"
}
}
}
}
```
This project was generated by express-generator,
the file of WWW
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('nodezy1390qs:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
My mongodb database
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var dbUrl = "mongodb://wusongQuestion:L****@127.0.0.1:/question-system"
if(env === "development"){
mongoose.connect('mongodb://localhost/question-system');
}
mongoose.connect(dbUrl);
exports.mongoose = mongoose
Now I run command line: 'pm2 deploy ecosystem.json production', but it shows me
I have no idea, probably The root of the problem lies in my source code,
via WUSO01
No comments:
Post a Comment