concept new user in category node

appears as: new users, new user
Get Programming with Node.js

This is an excerpt from Manning's book Get Programming with Node.js.

  • Unit 5 helps you build code to represent user accounts in an object-oriented structure. In this unit, you learn about securing your data and building a login form for new users.
  • Listing 18.3. Creating a new user in REPL in terminal
    var testUser;
    User.create({
      name: {
        first: "Jon",
        last: "Wexler"
      },
      email: "jon@jonwexler.com",
      password: "pass123"
    })
      .then(user => testUser = user)
      .catch(error => console.log(error.message));         #1

    To create a new user instance in your database, you need some way of retrieving that user’s data. So far, you’ve been entering that data directly in REPL. Because you’re moving all your data interactions to the browser, you need a form through which new users can create their accounts. In CRUD terms, that form lives in a view called new.ejs.

    19.2. Creating new users from a view

    The form for new users collects data as it pertains to the user schema. Next, you need to create actions for this form. To get your form to render and process data, add the code for the user actions in listing 19.2 to usersController.js.

    The new action takes incoming requests to create a new user and render the form in new.ejs. The create action receives incoming posted data from the form in new.ejs and passes the resulting created user to the next middleware function through the response object. The next middleware function, redirectView, determines which view to show based on the redirect path it receives as part of the response object. If a user is created successfully, redirect to the index page.

    Node.js in Action, Second Edition

    This is an excerpt from Manning's book Node.js in Action, Second Edition.

    You can make the debugger break by adding a debugger statement anywhere in your code. When the debugger statement is encountered, the debugger will halt, allowing you to issue commands. Imagine you’ve written a REST API that creates accounts for new users, and your user creation code doesn’t seem to be persisting the new user’s password hash to the database. You could add debugger to the save method in the User class, and then step over each instruction to see what happens.

    You need only a small amount of code in the submission route to handle validation, such as ensuring that the username isn’t already taken, and to save the new user, as listing 6.24 shows.