Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js npm错误!缺少脚本:开始_Node.js_Heroku_Mean Stack - Fatal编程技术网

Node.js npm错误!缺少脚本:开始

Node.js npm错误!缺少脚本:开始,node.js,heroku,mean-stack,Node.js,Heroku,Mean Stack,我在尝试将我的节点应用程序部署到heroku时遇到“npm ERR!缺少脚本:start”。我如何解决这个问题?heroku日志如下图所示(我是一个暴发户) heroku原木 2018-08-13T20:31:05.696247+00:00 app[api]: Initial release by user me@gmail.com 2018-08-13T20:31:05.696247+00:00 app[api]: Release v1 created by user me@g

我在尝试将我的节点应用程序部署到heroku时遇到“npm ERR!缺少脚本:start”。我如何解决这个问题?heroku日志如下图所示(我是一个暴发户)

heroku原木

    2018-08-13T20:31:05.696247+00:00 app[api]: Initial release by user me@gmail.com
    2018-08-13T20:31:05.696247+00:00 app[api]: Release v1 created by user me@gmail.com
    2018-08-13T20:31:06.029459+00:00 app[api]: Release v2 created by user me@gmail.com
    2018-08-13T20:31:06.029459+00:00 app[api]: Enable Logplex by user me@gmail.com
    2018-08-13T20:32:58.000000+00:00 app[api]: Build started by user me@gmail.com
    2018-08-13T20:33:23.424827+00:00 app[api]: Deploy 27a92d9a by user me@gmail.com
    2018-08-13T20:33:23.505334+00:00 app[api]: Scaled to web@1:Free by me@gmail.com
    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 me@gmail.com
    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}`);
    });
小结:在提出这个问题之前,我已经查看了建议的链接,但这无助于解决问题

更新:已解决。
无法解释这是如何解决的,但我放弃了repo并重新初始化解决了它。

您的
包.json
文件中是否有脚本

可能重复:是的,其中有一个脚本,将start设置为我的条目文件(“start”:“node app.js”)。谢谢你的回复,KaraNyyan。你能分享这个文件吗?还要检查Procfile是否配置良好。我已经编辑了我的帖子,添加了package.json和app.js文件。谢谢你的帮助。