lundi 7 septembre 2015

Fail to deploy my own nodejs to aws elastic bean stalk

I have a valid node.js app that I want to deploy to AWS EB. It is valid because it is working on my localhost by:

npm start

The zip that I upload looks like this:

folder structure

My app.js looks like:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mysql = require('mysql');
var sequelize = require('sequelize');

var routes = require('./routes/index');
var users = require('./routes/users');
var responseDTO = require('./dto/httpResponseDTO.js');

var app = express();

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handlers
app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    msg = responseDTO.toReseponseDTO(false, err.name, err.errors);
    res.json(msg);
});


module.exports = app;

The package.json looks like:

{
    "name" : #projectname#,
    "version" : "0.1.1",
    "private" : true,
    "scripts" : {
            "start" : "node ./bin/www"
    },
    "dependencies" : {
        "body-parser" : "~1.13.2",
        "cookie-parser" : "~1.3.5",
        "debug" : "~2.2.0",
        "express" : "~4.13.1",
        "jade" : "~1.11.0",
        "morgan" : "~1.6.1",
        "serve-favicon" : "~2.3.0",
        "mysql" : "^2.5.4",
        "sequelize" : "3.5.1",
        "emailjs": "^0.x"
    }
}

It looks like this is causing problem to EB, which says:

Impaired services on all instances.

The error log says:

Server running at http://127.0.0.1:8081/
Server running at http://127.0.0.1:8081/
npm ERR! Linux 3.14.48-33.39.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.6-linux-x64/bin/npm" "start"
npm ERR! node v0.12.6
npm ERR! npm  v2.11.2
npm ERR! path /var/app/current/package.json
npm ERR! code ENOENT
npm ERR! errno -2

npm ERR! enoent ENOENT, open '/var/app/current/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/npm-debug.log
npm ERR! Linux 3.14.48-33.39.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v0.12.6-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v0.12.6-linux-x64/bin/npm" "start"
npm ERR! node v0.12.6
npm ERR! npm  v2.11.2
npm ERR! path /var/app/current/package.json
npm ERR! code ENOENT
npm ERR! errno -2

It looks like the package.json isn't found? but from the folder structure it is there...

Please let me know what went wrong, it has been bothering me for a long time!




2 commentaires:

  1. Hi Lundi, i have the same issue, any solution or workaround?

    RépondreSupprimer
  2. Hi Lundi, i have the same issue, any solution or workaround?

    RépondreSupprimer