I am writing an application with the Node.js, Express.js, and Jade combination.
I have file client.js
, which is loaded on the client. In that file I have code that calls functions from other JavaScript files. My attempt was to use
var m = require('./messages');
in order to load the contents of messages.js
(just like I do on the server side) and later on call functions from that file. However, require
is not defined on the client side, and it throws an error of the form Uncaught ReferenceError: require is not defined
.
These other JavaScript files are also loaded at runtime at the client, because I place the links at the header of the webpage. So the client knows all the functions that are exported from these other files.
How do I call these functions from these other JavaScript files (such as messages.js
) in the main client.js
file that opens the socket to the server?
<script src="messages.js"></script>
and call them after that? – Sterling Archer--require
option causesrequire()
to be defined on the client side. See: lincolnloop.com/blog/speedy-browserifying-multiple-bundles – Hephaestus