title: Use node js as backend for ionic framework
body: <p>I followed the following tutorial to create a RESTApi for my node server...<a href="https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4" rel="nofollow">https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4</a></p>
  
  <p>My server file now has routes that allow it to to make GET and POST requests which I've tested on Postman and they work. My server file is pretty long but here is an excerpt to get an idea of how it works...</p>
  
  <pre><code>router.route('/bears')
      // create a bear (accessed at POST http://localhost:8080/api/bears)
      .post(function(req, res) {
  
          var bear = new Bear();      // create a new instance of the Bear model
          bear.name = req.body.name;  // set the bears name (comes from the request)
  
          // save the bear and check for errors
          bear.save(function(err) {
              if (err)
                  res.send(err);
  
              res.json({ message: 'Bear created!' });
          });
  
      })
      .get(function(req, res) {
          Bear.find(function(err, bears) {
              if (err)
                  res.send(err);
  
              res.json(bears);
          });
      });
  router.route('/bears/:bear_id')
  
          // get the bear with that id (accessed at GET http://localhost:8080/api/bears/:bear_id)
          .get(function(req, res) {
              Bear.findById(req.params.bear_id, function(err, bear) {
                  if (err)
                      res.send(err);
                  res.json(bear);
              });
          });
  ...etc,etc
  </code></pre>
  
  <p>Now, since I am using an ionic framework I need to configure it to use this server as a backend.</p>
  
  <p>My problem is, how do I connect to it using angular?</p>
  
  <p>All my routes are prefixed using <code>/api</code></p>
  
  <pre><code>app.use('/api', router);
  </code></pre>
  
  <p>So I tried the following...</p>
  
  <pre><code>app.factory('Bear', function ($resource) {
      return $resource('http://XXX.XXX.X.XX:3000/api/bears/:bearId');
  });
  </code></pre>
  
  <p>But I'm not sure this is working. I want to make one Post request so that I can test that the backend is working but I do not know what code to add to do so.</p>
  
  <p>For example, if I have a form on my <code>index.html</code> and I send this info to my angular controller, how can my controller take this info and make a post request to my server? I've been trying to figure this out for days.</p>