2

I've written a basic node.js application, it's working on local with the command : node app.js but not in heroku here is my package.json

{
  "name": "express-rest-youness",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "express": "^4.16.2",
    "express-rest": "^1.0.4"
  }
}

and my app.js

 var express = require('express'),
    expressRest = require('express-rest');

 var app = express();
var rest = expressRest(app);

var records = [
    {value: 'Apple'},
    {value: 'Banana'}
];

rest.get('/api/food', function(req, rest) {
    rest.ok(records);
});

rest.get('/api/food/:id', function(req, rest) {
    var record = records[req.params.id];
    if (record) rest.ok(record);
    else rest.notFound();
});

rest.put('/api/food/:id', function(req, rest) {
    records[req.params.id] = req.body;
    return rest.accepted('/api/food/' + encodeURI(req.params.id));
});

rest.post('/api/food', function(req, rest) {
    records.push(req.body);
    rest.created('/api/food/' + (records.length - 1));
});

rest.delete('/api/food/:id', function(req, rest) {
    delete records[req.params.id];
    rest.gone();
})


app.listen(8080);

when trying to access the heroku app i get :

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.

Thanks :)

2 Answers 2

3

Have you created a Procfile? I'd suggest to familiarize yourself with this tutorial.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, worked, i read before asking about the procfile but i was excepting the heroku run node app.js to work too .. anyway thanks a lot :)
@YounessHoudass you're very welcome. Would you mark my answer as the solution please ;)
0

I solved it by logging in into heroku dashboard and then app settings and there i specified config vars

1 Comment

You need to get more information on what the error is, such as requesting for the log message, then you can tell if this proffered solution fits into this scenario

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.