Question

I'm building a user registration / authentication system in Node.js. On the registration form, the user is prompted to type their email, password, and confirm their password. Before sending the email and the password to the server to be encrypted and stored, I want to check whether the password strings match. I don't want to send both passwords to Node.js to have it check whether they match. Instead, I want to compare the password field values on the client-side, and only submit once the passwords match. I'm using EJS as my templating engine.

  • How can I run client-side Javascript on a page loaded from Node.js? This seems like it should be a simple question, but in 3 days' searching, I haven't found a good answer.

  • How can I include jQuery for selectors and event handlers for this code?

Was it helpful?

Solution

Exactly the same as you'd do it for a non-Node.js project: use the <script> tag in your EJS to include a javascript file (or code).

OTHER TIPS

To execute the javascript logic you've written in node on the client I recommend running it through http://browserify.org/.

This will enable you to use the same logic written in node on the client.

Also, you can npm install jquery:

var $ = require('jquery');

For your client side bundle. But yes you will still need to serve the build javascript with a script tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top