Reputation: 21
I want a JavaScript file to be included in my client as well as server.
Having some issues. Please help me.
Code:
require('app.js');
or
<script src='app.js'></script>
Which one should I use?
Upvotes: 2
Views: 243
Reputation: 915
You can use Browserify to bundle your node module then import that js file with:
<script src='app.js'></script>
The require()
function will now be on the global namespace and you can call the following to make the module available to use:
var app = require('app.js');
Note: in Browserify you'll need to export the module you want to import using require.
Upvotes: 1