Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Hapi accessing server from other js file

I'm more or less new to JS in general and am currently trying to figure out how and why I do not have access to a previously defined server attribute.

In another file I attempt to import

const server = require('./..');

points to the right location as far as I can tell, and all other variables set in a similar manner work fine.

I'm assuming this is an issue in the server registration part of things with Hapi.

const init = async () => {
  // Load dependencies
  require('./conf/os.conf')();
  require('./middleware');
  const model = require('./model');
  require('./routes');
  require('./workers');
  const server = module.exports = Hapi.server({
    port: process.env.PORT,
  });
  await server.register([
    require('hapi-async-handler'),
    require('hapi-auth-bearer-token'),
    require('hapi-overriding'),
    require('inert'),
    require('vision'),
    {
      register: require('hapi-swagger'),
      options: {
        documentationPath: `${process.env.API_BASEURL}/documentation`,
        info: {
          title: 'API Documentation',
          version: process.env.API_VERSION,
          contact: {
            name: 'Mason Fraser',
            email: 'myemail@email.com'
          }
        },
        pathPrefixSize: 3,
        basePath: `${process.env.API_BASEURL}/`
      }
    }, {
      register: require('hapi-pagination'),
      options: {
        query: {
          pagination: {
            default: false
          }
        },
        meta: {
          baseUri: process.env.API_BASEURL,
          limit: {
            active: true
          },
          page: {
            active: true
          }
        }
      }
    }
  ]);
  // Trying things.
  exports.plugin = {
    register: (server, options) => {
      server,
      require('hapi-async-handler'),
      require('hapi-auth-bearer-token'),
      require('hapi-overriding'),
      require('inert'),
      require('vision')
    }
  }
  await server.start();
  console.log('Server running on %s', server.info.uri);
};

Any clues on how to fix this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!