Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

iife is a better way #203

Closed
iraniamir opened this issue Feb 7, 2018 · 1 comment
Closed

iife is a better way #203

iraniamir opened this issue Feb 7, 2018 · 1 comment
Labels

Comments

@iraniamir
Copy link

main();

you can invoke immediately for server.js like this :

'use strict';
const Glue = require('glue');
const Manifest = require('./manifest');


process.on('unhandledRejection', (reason, promise) => {

    console.error(`Unhandled Rejection at: ${promise} reason: ${reason}`);
});


const main = (async function () {

    const options = { relativeTo: __dirname };
    const server = await Glue.compose(Manifest.get('/'), options);

    await server.start();

    console.log(`Server started on port ${Manifest.get('/server/port')}`);
})();
@jedireza
Copy link
Owner

jedireza commented Feb 8, 2018

It's a another way 😉

And in that case you can remove const main = too.

(async function () {

    const options = { relativeTo: __dirname };
    const server = await Glue.compose(Manifest.get('/'), options);

    await server.start();

    console.log(`Server started on port ${Manifest.get('/server/port')}`);
})();

One might also elect to wrap main(); in a try/catch or handle it's promise like main().then(...).catch(...). I expect this to be customized per project.

@jedireza jedireza closed this as completed Feb 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants