Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent require()ing executable-only files #789

Closed
nfischer opened this issue Oct 19, 2017 · 1 comment
Closed

Prevent require()ing executable-only files #789

nfischer opened this issue Oct 19, 2017 · 1 comment
Assignees

Comments

@nfischer
Copy link
Member

@nfischer nfischer commented Oct 19, 2017

This was a point raised in #786. We can prevent require()ing files with:

if (require.main === module) {
    // everything goes here
}

This might be a good idea for files which we only intend to execute (e.g. bin/shjs).

I would also consider rewriting as:

if (require.main !== module) {
  throw new Error('Module should not be required');
}
// everything goes here
@freitagbr
Copy link
Contributor

@freitagbr freitagbr commented Oct 19, 2017

Failing loudly sounds like a good behavior. That way, you can't even accidentally require the file without node exiting.

@freitagbr freitagbr self-assigned this May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants