O'Reilly logo

Node.js Essentials by Fabian Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hello require

In the preceding example, we just logged a simple message, nothing interesting, so let's dive a bit deeper in this section.

When using multiple scripts in the browser, we usually just include another script tag such as:

<script type='application/javascript' src='script_a.js'></script>
<script type='application/javascript' src='script_b.js'></script>

Both these scripts share the same global scope, this usually leads to some unusual conflicts when people want to give variables the same name.

//script_a.js
function run( ) {
    console.log( "I'm running from script_a.js!" );
}
$( run );

//script_b.js
function run( ) {
    console.log( "I'm running from script_b.js!" );
}
$( run );

This can lead to confusion, and when many files are minified and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required