PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 15, 2022

[FIXED] How to configure index.js with hapi npm for deployment

 July 15, 2022     heroku, node.js, package.json, web-deployment     No comments   

Issue

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


Solution

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:



Answered By - ArunPratap
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing