-1

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?

  • post the code maybe? – user2717954 Aug 31 '15 at 08:56
  • Also, try googling your question first before posting it: http://stackoverflow.com/questions/29873988/resolve-uncaught-referenceerror-require-is-not-defined-error-in-node-js , http://stackoverflow.com/questions/8404562/node-js-require-is-not-defined-exception , http://stackoverflow.com/questions/19059580/client-on-node-uncaught-referenceerror-require-is-not-defined – Blaž Zupančič Aug 31 '15 at 09:02

1 Answers1

1

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.

jfriend00
  • 683,504
  • 96
  • 985
  • 979