How to configure index.js with hapi npm for deployment












0















I received this project to deploy, which uses the hapi npm that I am not familiar with. I am able to run it successfully localy but when I try to deploy it I get an error, on heroku the error is:



npm ERR! missing script: start


I think maybe I have to change something in the index.js maybe the port or the host inside server const?
Here is my index.js



const Hapi = require('hapi');
const path = require('path');
const fs = require('fs');
const util = require('util');


const readDir = util.promisify(fs.readdir);

const server = Hapi.server({
port: 3000,
host: 'localhost',
routes: {
files: {
relativeTo: path.join(__dirname, 'public')
}
}
})

const start = async () => {
await server.register(require('vision'));
await server.register(require('inert'));

server.views({
engines: {
html: require('handlebars')
},
relativeTo: __dirname,
path: 'templates',
layout: 'layout-other',
layoutPath: 'templates/layout'
});

// Static files
server.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: path.join(__dirname, 'public'),
listing: true
}
}
});

require('./routes')(server);

server.start();
}

start();


Thanks










share|improve this question





























    0















    I received this project to deploy, which uses the hapi npm that I am not familiar with. I am able to run it successfully localy but when I try to deploy it I get an error, on heroku the error is:



    npm ERR! missing script: start


    I think maybe I have to change something in the index.js maybe the port or the host inside server const?
    Here is my index.js



    const Hapi = require('hapi');
    const path = require('path');
    const fs = require('fs');
    const util = require('util');


    const readDir = util.promisify(fs.readdir);

    const server = Hapi.server({
    port: 3000,
    host: 'localhost',
    routes: {
    files: {
    relativeTo: path.join(__dirname, 'public')
    }
    }
    })

    const start = async () => {
    await server.register(require('vision'));
    await server.register(require('inert'));

    server.views({
    engines: {
    html: require('handlebars')
    },
    relativeTo: __dirname,
    path: 'templates',
    layout: 'layout-other',
    layoutPath: 'templates/layout'
    });

    // Static files
    server.route({
    method: 'GET',
    path: '/{param*}',
    handler: {
    directory: {
    path: path.join(__dirname, 'public'),
    listing: true
    }
    }
    });

    require('./routes')(server);

    server.start();
    }

    start();


    Thanks










    share|improve this question



























      0












      0








      0








      I received this project to deploy, which uses the hapi npm that I am not familiar with. I am able to run it successfully localy but when I try to deploy it I get an error, on heroku the error is:



      npm ERR! missing script: start


      I think maybe I have to change something in the index.js maybe the port or the host inside server const?
      Here is my index.js



      const Hapi = require('hapi');
      const path = require('path');
      const fs = require('fs');
      const util = require('util');


      const readDir = util.promisify(fs.readdir);

      const server = Hapi.server({
      port: 3000,
      host: 'localhost',
      routes: {
      files: {
      relativeTo: path.join(__dirname, 'public')
      }
      }
      })

      const start = async () => {
      await server.register(require('vision'));
      await server.register(require('inert'));

      server.views({
      engines: {
      html: require('handlebars')
      },
      relativeTo: __dirname,
      path: 'templates',
      layout: 'layout-other',
      layoutPath: 'templates/layout'
      });

      // Static files
      server.route({
      method: 'GET',
      path: '/{param*}',
      handler: {
      directory: {
      path: path.join(__dirname, 'public'),
      listing: true
      }
      }
      });

      require('./routes')(server);

      server.start();
      }

      start();


      Thanks










      share|improve this question
















      I received this project to deploy, which uses the hapi npm that I am not familiar with. I am able to run it successfully localy but when I try to deploy it I get an error, on heroku the error is:



      npm ERR! missing script: start


      I think maybe I have to change something in the index.js maybe the port or the host inside server const?
      Here is my index.js



      const Hapi = require('hapi');
      const path = require('path');
      const fs = require('fs');
      const util = require('util');


      const readDir = util.promisify(fs.readdir);

      const server = Hapi.server({
      port: 3000,
      host: 'localhost',
      routes: {
      files: {
      relativeTo: path.join(__dirname, 'public')
      }
      }
      })

      const start = async () => {
      await server.register(require('vision'));
      await server.register(require('inert'));

      server.views({
      engines: {
      html: require('handlebars')
      },
      relativeTo: __dirname,
      path: 'templates',
      layout: 'layout-other',
      layoutPath: 'templates/layout'
      });

      // Static files
      server.route({
      method: 'GET',
      path: '/{param*}',
      handler: {
      directory: {
      path: path.join(__dirname, 'public'),
      listing: true
      }
      }
      });

      require('./routes')(server);

      server.start();
      }

      start();


      Thanks







      node.js heroku web-deployment package.json






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 12:23









      ArunPratap

      2,1312928




      2,1312928










      asked Nov 28 '18 at 10:29









      Jack Jack

      959




      959
























          2 Answers
          2






          active

          oldest

          votes


















          1














          missing script: start. In your package.json, means you are missing to configure where to start
          check your package.json file you should define that like this



          "scripts": {
          "start": "node index.js"
          }



          If your app has a build step that you’d like to run when you deploy, you can use a Postinstall script in package.json:







          share|improve this answer

































            1














            npm start is a script that is created in your package.json file.
            You can check more about it here



            An example of a package.json file:



            {
            "name": "node-js-sample",
            "version": "0.2.0",
            "description": "A sample Node.js app using Express 4",
            "main": "index.js",
            "scripts": {
            "start": "node index.js",
            "somescript":"do something"
            },
            "dependencies": {
            "express": "^4.13.3"
            },
            "license": "MIT"
            }


            npm start will run the "start" script. Which means it will run node index.js
            npm somescript will run the "somescript" script. Which means it will run do something






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53517306%2fhow-to-configure-index-js-with-hapi-npm-for-deployment%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              missing script: start. In your package.json, means you are missing to configure where to start
              check your package.json file you should define that like this



              "scripts": {
              "start": "node index.js"
              }



              If your app has a build step that you’d like to run when you deploy, you can use a Postinstall script in package.json:







              share|improve this answer






























                1














                missing script: start. In your package.json, means you are missing to configure where to start
                check your package.json file you should define that like this



                "scripts": {
                "start": "node index.js"
                }



                If your app has a build step that you’d like to run when you deploy, you can use a Postinstall script in package.json:







                share|improve this answer




























                  1












                  1








                  1







                  missing script: start. In your package.json, means you are missing to configure where to start
                  check your package.json file you should define that like this



                  "scripts": {
                  "start": "node index.js"
                  }



                  If your app has a build step that you’d like to run when you deploy, you can use a Postinstall script in package.json:







                  share|improve this answer















                  missing script: start. In your package.json, means you are missing to configure where to start
                  check your package.json file you should define that like this



                  "scripts": {
                  "start": "node index.js"
                  }



                  If your app has a build step that you’d like to run when you deploy, you can use a Postinstall script in package.json:








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 19 '18 at 9:39

























                  answered Nov 28 '18 at 10:39









                  ArunPratapArunPratap

                  2,1312928




                  2,1312928

























                      1














                      npm start is a script that is created in your package.json file.
                      You can check more about it here



                      An example of a package.json file:



                      {
                      "name": "node-js-sample",
                      "version": "0.2.0",
                      "description": "A sample Node.js app using Express 4",
                      "main": "index.js",
                      "scripts": {
                      "start": "node index.js",
                      "somescript":"do something"
                      },
                      "dependencies": {
                      "express": "^4.13.3"
                      },
                      "license": "MIT"
                      }


                      npm start will run the "start" script. Which means it will run node index.js
                      npm somescript will run the "somescript" script. Which means it will run do something






                      share|improve this answer




























                        1














                        npm start is a script that is created in your package.json file.
                        You can check more about it here



                        An example of a package.json file:



                        {
                        "name": "node-js-sample",
                        "version": "0.2.0",
                        "description": "A sample Node.js app using Express 4",
                        "main": "index.js",
                        "scripts": {
                        "start": "node index.js",
                        "somescript":"do something"
                        },
                        "dependencies": {
                        "express": "^4.13.3"
                        },
                        "license": "MIT"
                        }


                        npm start will run the "start" script. Which means it will run node index.js
                        npm somescript will run the "somescript" script. Which means it will run do something






                        share|improve this answer


























                          1












                          1








                          1







                          npm start is a script that is created in your package.json file.
                          You can check more about it here



                          An example of a package.json file:



                          {
                          "name": "node-js-sample",
                          "version": "0.2.0",
                          "description": "A sample Node.js app using Express 4",
                          "main": "index.js",
                          "scripts": {
                          "start": "node index.js",
                          "somescript":"do something"
                          },
                          "dependencies": {
                          "express": "^4.13.3"
                          },
                          "license": "MIT"
                          }


                          npm start will run the "start" script. Which means it will run node index.js
                          npm somescript will run the "somescript" script. Which means it will run do something






                          share|improve this answer













                          npm start is a script that is created in your package.json file.
                          You can check more about it here



                          An example of a package.json file:



                          {
                          "name": "node-js-sample",
                          "version": "0.2.0",
                          "description": "A sample Node.js app using Express 4",
                          "main": "index.js",
                          "scripts": {
                          "start": "node index.js",
                          "somescript":"do something"
                          },
                          "dependencies": {
                          "express": "^4.13.3"
                          },
                          "license": "MIT"
                          }


                          npm start will run the "start" script. Which means it will run node index.js
                          npm somescript will run the "somescript" script. Which means it will run do something







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 28 '18 at 10:42









                          Aritra ChakrabortyAritra Chakraborty

                          2,43811015




                          2,43811015






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53517306%2fhow-to-configure-index-js-with-hapi-npm-for-deployment%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Contact image not getting when fetch all contact list from iPhone by CNContact

                              count number of partitions of a set with n elements into k subsets

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks