title: TypeError: require(...) is not a function
body: <p>I'm getting the following error:</p>
  
  <pre><code>var userModel = require("./models/user.model.js")();
                                                   ^
  
  TypeError: require(...) is not a function
  at module.exports 
  at Object.&lt;anonymous&gt; 
  at Module._compile (module.js:435:26)
  at Object.Module._extensions..js (module.js:442:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:311:12)
  at Function.Module.runMain (module.js:467:10)
  at startup (node.js:136:18)
  </code></pre>
  
  <p>when I try to <code>require</code> 2 files, using the following code:</p>
  
  <pre><code>module.exports = function (app) {
    "use strict";
  
    var userModel = require("./models/user.model.js")();
    var formModel = require("./models/form.model.js")();
  
    require("./services/user.service.server.js")(app, userModel);
    require("./services/form.service.server.js")(app, formModel);
    require("./services/field.service.server.js")(app, formModel);
  };
  </code></pre>
  
  <p>I'm new to this and I can't understand the problem. Can someone please explain it to me and help me find a solution?</p>
  
  <p><strong>EDIT:</strong> Adding user.services.server.js:</p>
  
  <pre><code>module.exports = function(app, userModel) {
  "use strict";
  
  app.post('/api/assignment/user', createUser);
  app.get('/api/assignment/user', findUsers);
  app.get('/api/assignment/user/:id', findUserById);
  app.put("/api/assignment/user/:userId", updateUserById);
  app.delete("/api/assignment/user/:userId", deleteUserById);
  
  function createUser(req, res) {
      var newUser = userModel.createUser(req.body);
      res.json(newUser);
  }
  
  function findUsers(req, res) {
      if (req.query.username) {
          if (req.query.password) {
              findUserByCredentials(req, res);
          } else {
              findUserByUsername(req, res);
          }
      } else {
          var users = userModel.findAllUsers();
          res.json(users);
      }
  }
  
  function findUserById(req, res) {
      var userId = parseInt(req.params.id);
      var user = userModel.findUserById(userId);
      res.json(user);
  }
  
  function findUserByUsername(req, res) {
      var username = req.query.username;
      var user = userModel.findUserByUsername(username);
      res.json(user);
  }
  
  function findUserByCredentials(req, res) {
      var credentials = {
          username: req.query.username,
          password: req.query.password
      };
      var user = userModel.findUserByCredentials(credentials);
      res.json(user);
  }
  
  function updateUserById(req, res) {
      var userId = parseInt(req.params.id);
      var newUser = userModel.updateUser(userId, req.body);
      res.json(newUser);
  }
  
  function deleteUserById(req, res) {
      var userId = parseInt(req.params.id);
      userModel.deleteUser(userId);
      res.send(200);
  }
  
  }();
  </code></pre>