1

I've made my first node js application on localhost :) It's an API, and it works perfectly on localhost: I typed "http://localhost:8080/home?star=3333" on address bar and got:

{"Bezeq":"תפוס","Hot":"תפוס","Cellcom":"לא פנויה","Partner":"תפוס"}

(It does what It's supposed to do)

I deployed my folder to Heroku and after some problems, I've managed to do it successfully. I've made a Procfile (I watch a tutorial that said it's necessary...) and changed my port number to process.env.PORT.
After all that, I thought I'm done, but unfortunately that is not the case.
When trying to open my app at "https://my-app-name.herokuapp.com/home?number=3333" I get this: Internal Server Error.
My logs:


2019-07-04T09:41:24.651145+00:00 app[web.1]: TypeError: Cannot read property 'toString' of undefined
2019-07-04T09:41:24.651168+00:00 app[web.1]: at /app/MainAPI.js:7:35
2019-07-04T09:41:24.651171+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.651172+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2019-07-04T09:41:24.651173+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2019-07-04T09:41:24.651174+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.651176+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2019-07-04T09:41:24.651177+00:00 app[web.1]: at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
2019-07-04T09:41:24.651177+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/index.js:275:10)
2019-07-04T09:41:24.651179+00:00 app[web.1]: at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
2019-07-04T09:41:24.651179+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-07-04T09:41:24.649937+00:00 heroku[router]: at=info method=GET path="/home?number=3333" host=star-status.herokuapp.com request_id=b1b9b421-92bf-4394-a076-4a2d1056c805 fwd="216.72.40.6" dyno=web.1 connect=1ms service=2ms status=500 bytes=404 protocol=https

Package.json:

{
  "name": "my-app-name",
  "version": "1.0.0",
  "description": "",
  "main": "MainAPI.js",
  "dependencies": {
    "express": "^4.17.1",
    "table-scraper": "^0.1.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

MainAPI.js:

const http = require('http');
const express = require('express');
var app = express();

app.listen(process.env.PORT || 8080);
app.get('/home', function (req, res) {
    getStarsStatus(req.query.star.toString(),()=>{
        res.end(JSON.stringify(statuses));
    });
});

var statuses = {
    'Bezeq': '',
    'Hot': '',
    'Cellcom': '',
    'Partner': ''
};

function getStarsStatus(star, callback) {

    let numStatusesFetched = 0;
    require('./Bezeq').GetStarStatus(star, function(status) {
        statuses['Bezeq'] = status;
        numStatusesFetched++;
        if(numStatusesFetched == 4) callback();
    });

    require('./Hot').GetStarStatus(star, function(status){
    statuses['Hot'] = status[0][0]['סטטוס'];
    numStatusesFetched++;
        if(numStatusesFetched == 4) callback();
    });

    require('./Partner').GetStarStatus(star, function(status) {
        statuses['Partner'] = status;
        numStatusesFetched++;
        if(numStatusesFetched == 4) callback();

    });

    require('./Cellcom').GetStarStatus(star, function(status) {
        statuses['Cellcom'] = status;
        numStatusesFetched++;
        if(numStatusesFetched == 4) callback();
    });

}

Does someone have an idea for why it doesn't work?
Thank You!

8
  • more logs please? before those you posted, there should be some explaining your error Commented Jul 4, 2019 at 9:25
  • This is all I have... Correct me if I'm wrong: Heroku > my-app-name > more > view logs Commented Jul 4, 2019 at 9:28
  • correct, "all processes" from the dropdown. Are the logs scrollable? Commented Jul 4, 2019 at 9:31
  • Please, use heroku logs in your app folder or add PaperTrail plugin to your app on Heroku (free) to view the complete logs and paste it here. Commented Jul 4, 2019 at 9:34
  • Could you please share the package.json and conde snipped for server start (may be index.js or server.js). Commented Jul 4, 2019 at 9:35

1 Answer 1

1

OMG, I'm so stupid..
I typed number=3333 instead of star=3333..
Thank You Everybody

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

Comments

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.