I'm trying to learn expressjs.
I have a script inside the public/javascripts
folder with a require
call.
The browser is reporting that require is not defined
.
How can I solve it?
I'm trying to learn expressjs.
I have a script inside the public/javascripts
folder with a require
call.
The browser is reporting that require is not defined
.
How can I solve it?
require()
is something that you use with expressjs on your server in your nodejs code, not in your browser pages.
Scripts in your browser pages are generally loaded with <script>
tags, though there are loading libraries that can be used to provide require()
like functionality in the browser, but those are not needed to use expressjs for your server.
Probably your solution is to use a <script>
tag in the web page to specify the script you want loaded in that web page and to add some express.static()
routes in your expressjs code to instruct your nodejs server to serve the scripts in the script directory to your web pages.
With more detail about what you're trying to do, a more specific answer could be provided.
I'd suggest reading about Serving Static Files in Express.