> For the complete documentation index, see [llms.txt](https://eleven-fifty-academy.gitbook.io/javascript-152-nodeserver/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eleven-fifty-academy.gitbook.io/javascript-152-nodeserver/js_library/node-server/06-tokenization/02-user-create/02-refactor.md).

# 02 - Refactor

In this module, we'll refactor the user create controller method.

## Refactor

Refactoring is just part of the game. We work in iterations. You write methods, you add to them, you take things away. In this chapter, you won't be rebuilding a POST controller method in seven steps like we did last time. Let's do a quick refactor:

```javascript
router.post('/createuser', function (req, res) {

  var username = req.body.user.username;
  var pass = req.body.user.password;

  User.create({
    username: username,
    passwordhash: pass

  }).then(
    function createSuccess(user) {
      res.json({
        user: user,
        message: 'created' //1
      });
    },
    function createError(err) {
      res.send(500, err.message);
    }
  );
});

module.exports = router;
```

## Analysis

1. Along with the user object that gets returned as JSON, we can send a message in the response.
2. For the sake of time, we'll ask you to reread and review the flow of the above method. If you don't have an understanding, you'll want to review the information in the testcontroller in the `test/seven` method. One big difference here is that we have two properties instead of one. &#x20;

## Postman

Let's quickly test this iteration of the method with Postman.&#x20;

1\. Start your server then open Postman.&#x20;

2\. Figure out the endpoint to send a post request to.&#x20;

3\. Go to the body tab -> Choose Raw -> Change the dropdown to JSON.&#x20;

4\. Enter the request body: `{"user" : { "username": "kenn", "password":"linuxsirad" }}`.&#x20;

5\. You should see the response string:&#x20;

![screenshot](https://785407262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfspjIVOP2BrMNl%2F-LAU8cHEwYbpO3Obye5i%2F-LAU8o3WqvedhNT8OQSq%2F02-postman.PNG?generation=1524162326565695\&alt=media)

## Postgres

Check Postgres, too:&#x20;

![screenshot](https://785407262-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAU8YfspjIVOP2BrMNl%2F-LAU8cHEwYbpO3Obye5i%2F-LAU8kYKwHE_Nxt-laLv%2F02-postgres-user.PNG?generation=1524162311072444\&alt=media)

## Next

In the next module, we'll add a token to the response.
