-1

I am new to using Heroku to deploy REST api. I have coded a REST api in Node.JS now i want to deploy this to Heroku. Please is there a step by step method

i am getting this Error on Heroku

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. You can do this from the Heroku CLI with the command
heroku logs --tail

on my Desktop, testing on Postman it works perfectly. But i cannot view from a Browser

https://test-restapi2.herokuapp.com/employees

My Node.Js app looks like this :

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mysql = require('mysql');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended:true
}));

app.get('/',function(req , res){
    return res.send({error: true,message: 'hello'})
});

var dbConn = mysql.createConnection({
    host: 'xxxxxxxxxxxxxxxx',
    user: 'xxxxxxxxxxxxxx',
    password: 'xxxxxxxxxxx',
    database: 'xxxxxxxxxxxxxxxxx'
});

dbConn.connect();

app.get('/employees',function(req,res){
    dbConn.query('SELECT * FROM employeedb',function(error, results, fields){
        if (error) throw error;
        return res.send({ error: false, data: results, message: 'users list' });
    });
});



app.listen(5000,function(){
    console.log('App running on port 5000');
});

module.exports = app;

Please how Can i get this resolved?

Edits

Checking the Logs, I saw this :

    2021-10-09T19:28:55.666772+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-09T19:28:57.813040+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-09T19:28:59.202356+00:00 app[web.1]: npm ERR! missing script: start
2021-10-09T19:28:59.208564+00:00 app[web.1]: 
2021-10-09T19:28:59.208837+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-09T19:28:59.208892+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-10-09T19_28_59_202Z-debug.log
2021-10-09T19:28:59.327035+00:00 heroku[web.1]: Process exited with status 1
2021-10-09T19:28:59.422562+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-09T19:29:04.931511+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=test-restapi2.herokuapp.com request_id=aafd0e0b-988e-4673-9359-f7576e340d75 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:29:06.103970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=test-restapi2.herokuapp.com request_id=6b375048-c8db-4323-8484-ba60aafea022 fwd="154.120.87.9" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:15.776019+00:00 app[api]: Starting process with command `npm start` by user emeka1987ng@gmail.com
2021-10-09T19:32:17.857845+00:00 heroku[run.9636]: Awaiting client
2021-10-09T19:32:17.890327+00:00 heroku[run.9636]: Starting process with command `npm start`
2021-10-09T19:32:17.959936+00:00 heroku[run.9636]: State changed from starting to up
2021-10-09T19:32:21.444257+00:00 heroku[run.9636]: Process exited with status 1
2021-10-09T19:32:21.499239+00:00 heroku[run.9636]: State changed from up to complete
2021-10-09T19:32:28.775794+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=1a03731f-41cb-438d-b877-c1e49d5dd039 fwd="107.155.108.143" dyno= connect= service= status=503 bytes= protocol=https
2021-10-09T19:32:39.195421+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/employees" host=test-restapi2.herokuapp.com request_id=c1833124-6596-4401-a765-f8a65345b5e1 fwd="52.204.27.85" dyno= connect= service= status=503 bytes= protocol=https
Blaq
  • 53
  • 2
  • 10

1 Answers1

0

You can see the logs of your application and determine the problem.

At your project page, top right corner, there is a "More" button. Click there and then "View Logs" and you should be able to see the exact problem and fix it.

thanossav
  • 3
  • 1
  • Please see edits – Blaq Oct 09 '21 at 19:30
  • It seems like you havent set a "start" script in your package.json. So go there and under "scripts" add "start": "node your_file_name.js" – thanossav Oct 09 '21 at 19:36
  • in heroku? or local file? – Blaq Oct 09 '21 at 19:41
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 09 '21 at 19:52