2

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?

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.