V
V
Vitaly the Wise2017-07-07 12:03:10
Node.js
Vitaly the Wise, 2017-07-07 12:03:10

How to change current page and pass parameters to Node.js (Express)?

There is a code that processes data from the user registration form

let usersModel = require('../models/users');

exports.create = function(request, response) {
  usersModel.findByEmail(request.body.email, function(error, result) {
    if (error) {
      console.log(error);

      return response.render('pages/index', {
        createUser: {
          code: 500,
          first_name: request.body["first-name"],
          last_name: request.body["last-name"],
          email: request.body.email,
          region: request.body.region
        }
      });
    }

    if (result) {
      return response.render('pages/index', {
        createUser: {
          code: 210,
          first_name: request.body["first-name"],
          last_name: request.body["last-name"],
          email: request.body.email,
          region: request.body.region
        }
      });
    }

    let users = {
      first_name: request.body["first-name"],
      last_name: request.body["last-name"],
      email: request.body.email,
      region: request.body.region
    };

    usersModel.create(users, function(error, result) {
      if (error) {
        console.log(error);

        return response.render('pages/index', {
          createUser: {
            code: 500,
            first_name: request.body["first-name"],
            last_name: request.body["last-name"],
            email: request.body.email,
            region: request.body.region
          }
        });
      }

      return response.render('pages/index', {
        createUser: {
          code: 200
        }
      });
    });
  });
};

After processing, you need to go to the main page and pass the request execution parameters. I do so
return response.render('pages/index', {
        createUser: {
          code: 200
        }
      });

But in the address bar there is a path that is registered in the action property. Please help me fix this

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question