0

I am having "npm ERR! missing script: start" trying to deploy my node app to heroku. How can I resolve this? The heroku log is as shown below (I am an upstart wed dev.).

heroku logs

    2018-08-13T20:31:05.696247+00:00 app[api]: Initial release by user [email protected]
    2018-08-13T20:31:05.696247+00:00 app[api]: Release v1 created by user [email protected]
    2018-08-13T20:31:06.029459+00:00 app[api]: Release v2 created by user [email protected]
    2018-08-13T20:31:06.029459+00:00 app[api]: Enable Logplex by user [email protected]
    2018-08-13T20:32:58.000000+00:00 app[api]: Build started by user [email protected]
    2018-08-13T20:33:23.424827+00:00 app[api]: Deploy 27a92d9a by user [email protected]
    2018-08-13T20:33:23.505334+00:00 app[api]: Scaled to web@1:Free by [email protected]
    2018-08-13T20:33:24.000000+00:00 app[api]: Build succeeded
    2018-08-13T20:33:23.424827+00:00 app[api]: Release v3 created by user [email protected]
    2018-08-13T20:33:27.333267+00:00 heroku[web.1]: Starting process with command `npm start`
    2018-08-13T20:33:30.044912+00:00 heroku[web.1]: State changed from starting to crashed
    2018-08-13T20:33:30.046900+00:00 heroku[web.1]: State changed from crashed to starting
    2018-08-13T20:33:30.029816+00:00 heroku[web.1]: Process exited with status 1
    2018-08-13T20:33:29.947105+00:00 app[web.1]: npm ERR! missing script: start
    2018-08-13T20:33:29.957355+00:00 app[web.1]:
    2018-08-13T20:33:29.957645+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
    2018-08-13T20:33:29.957791+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-08-13T20_33_29_951Z-debug.log
    2018-08-13T20:33:33.578027+00:00 heroku[web.1]: Starting process with command `npm start`
    2018-08-13T20:33:37.209745+00:00 heroku[web.1]: Process exited with status 1
    2018-08-13T20:33:37.227965+00:00 heroku[web.1]: State changed from starting to crashed
    2018-08-13T20:33:37.072520+00:00 app[web.1]: npm ERR! missing script: start
    2018-08-13T20:33:37.096898+00:00 app[web.1]:
    2018-08-13T20:33:37.097307+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
    2018-08-13T20:33:37.097506+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-08-13T20_33_37_074Z-debug.log
    2018-08-13T20:34:00.858740+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ipt-restful-service.herokuapp.com request_id=88052f29-0130-4718-b6ed-fa4504c110fd fwd="41.58.247.5" dyno= connect= service= status=503 bytes= protocol=https
    2018-08-13T20:34:07.266783+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ipt-restful-service.herokuapp.com request_id=66190636-940a-40b9-999e-9edf1d7adb2a fwd="41.58.247.5" dyno= connect= service= status=503 bytes= protocol=https
    2018-08-13T20:34:07.270325+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ipt-restful-service.herokuapp.com request_id=bf8ba7ea-ecf7-4ead-a6a4-e66d959d7088 fwd="41.58.247.5" dyno= connect= service= status=503 bytes= protocol=https (edited)
    2018-08-13T21:03:57.706381+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ipt-restfuservices.herokuapp.com request_id=230a5e25-e3c6-4ac1-9b35-c52534c444d1 fwd="41.58.247.5" dyno= connect= service= status=503 bytes= protocol=https

package.js file

    {
      "name": "ipt-api",
      "version": "1.0.0",
      "description": "rest api using mongodb && express",
      "main": "app.js",
      "scripts": {
        "start": "node app.js"
      },
      "engines": {
        "node": "8.11.2"
      },
      "repository": {
        "type": "git"
      },
      "keywords": [
        "node",
        "heroku",
        "express"
      ],
      "author": "Bluebird",
      "license": "ISC",
      "dependencies": {
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.18.3",
        "crypto-js": "^3.1.9-1",
        "express": "^4.16.3",
        "jsonwebtoken": "^8.3.0",
        "lodash": "^4.17.10",
        "mongodb": "^3.1.1",
        "mongoose": "^5.2.5",
        "swagger-ui-express": "^3.0.10",
        "validator": "^10.4.0"
      },
      "devDependencies": {
        "expect": "^23.4.0",
        "mocha": "^5.2.0",
        "supertest": "^3.1.0"
      }
    }

app.js
    const express = require('express');
    const _ = require('lodash');
    const bodyParser = require('body-parser');
    const app = express();
    const swaggerUi = require('swagger-ui-express');
    const swaggerDocument = require('./swagger.json');
    var {User} = require('./models/users');
    var {mongoose} = require('./db/mongoose');
    var {ObjectID} = require('mongodb');
    var {authenticate} = require('./middleware/authenticate');
    app.use(bodyParser.json());
    const PORT = process.env.PORT || 3000;

    app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

    app.post('/create/user', (req, res) => {
       var createUser = new User({
           firstname:req.body.firstname,
           lastname:req.body.lastname,
           email:req.body.email,
           password:req.body.password,
           is_active:req.body.is_active,
           created_at:req.body.created_at,
           updated_at:req.body.updated_at
       });
       createUser.save().then(() => {
           return createUser.generateAuthToken();
       }).then((token) => {
           res.header('x-auth', token).status(200).send(createUser);
       }).catch((e) => {
           res.status(400).send(e);
       });
    });

    app.get('/users', authenticate, (req, res) => {
        User.find().then((data) => {
            res.status(200).send(req.data);
        });

    });

    app.get('/users/:id', (req, res) => {
        let id = req.params.id;
        if(!ObjectID.isValid(id)){
            return res.status(404).send({
                err:'not found'
            });
        }
        User.findById(id).then((data) => {
            if(!data){
                res.status(404).send('user not found');
            }
            res.status(200).send({
                status:'success',
                data
            });
        }, (e) => {
            res.status(400).send(e);
        });
    });

    app.patch('/users/update/:id', (req, res) => {
        let id = req.params.id;
        var body = _.pick(req.body, ['firstname', 'lastname', 'email', 'password', 'created_at', 'updated_at']);
        if(!ObjectID.isValid(id)){
            return res.status(404).send('user not found');
        }
        body.updated_at = new Date().getTime();
        User.findByIdAndUpdate(id, {$set:body}, {new:true}).then((data) => {
            if(!data){
                res.status(404).send('data not found');
            }
            res.status(200).send({
                status:'success',
                data
            });
        }, (e) => {
            res.status(400).send(e);
        });
    });

    app.patch('/users/update/status/:id', (req, res) => {
        let id = req.params.id;
        var body = _.pick(req.body, ['is_active']);
        if(!ObjectID.isValid(id)){
            return res.status(404).send('user not found');
        }
        if(_.isBoolean(body.is_active) && body.is_active){
            body.is_active = true;
        }else{
            body.is_ative = false;
        }
        User.findByIdAndUpdate(id, {$set:body}, {new:true}).then((data) => {
            if(!data){
                res.status(404).send('user not found');
            }
            res.status(200).send({
                status:'success',
                data
            });
        }, (e) => {
            res.status(400).send(e);
        });
    });

    app.delete('/users/delete/:id', (req, res) => {
        let id = req.params.id;
        if(!ObjectID.isValid(id)){
            return res.status(404).send('unable to process request');
        }
        User.findByIdAndRemove(id).then((data) => {
            if(!data){
                res.status(404).send('user not found');
            }
            res.status(200).send({
                status:'success',
                data
            });
        }, (e) => {
            res.status(400).send(e);
        });
    });

    app.post('/user/login', (req, res) => {
        var body = _.pick(req.body, ['email', 'password']);
        User.findByCredentials(body.email, body.password).then((data) => {
            res.status(200).send({
                status:'success',
                data
            });
        }).catch((e) => {
            res.status(400).send();
        });
    });
    module.exports = {app};

    app.listen(PORT, () => {
        console.log(`Application now listening to port ${PORT}`);
    });

Summary: I had looked at the link suggested as possible duplicate before raising this question but that did not help resolve the issue.

Update: Solved. Can not explain how this was a solution but I dropped the repo and re-init solved it.

1

1 Answer 1

1

Is there a script inside your package.json file ?

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

3 Comments

Yes, there is a script in there with start set to my entry file (as "start" : "node app.js"). thanks for the response, KaraNyyan.
Can you share this file ? Also check if the Procfile is well configured
I have edited my post adding the package.json and app.js files. Thanks for your help.

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.