title: Express router not working for post requests?
body: <p>I'm using angular-cli and webpack with following package.json configuration:</p>
  
  <pre><code>"dependencies": {
      "@angular/common": "^4.0.0",
      "@angular/compiler": "^4.0.0",
      "@angular/core": "^4.0.0",
      "@angular/forms": "^4.0.0",
      "@angular/http": "^4.0.0",
      "@angular/platform-browser": "^4.0.0",
      "@angular/platform-browser-dynamic": "^4.0.0",
      "@angular/router": "^4.0.0",
      "bcrypt-nodejs": "0.0.3",
      "body-parser": "^1.17.2",
      "core-js": "^2.4.1",
      "express": "^4.15.3",
      "express-session": "^1.15.4",
      "mongoose": "^4.11.3",
      "rxjs": "^5.1.0",
      "zone.js": "^0.8.4"
  } 
  </code></pre>
  
  <p>Below is my root folder structure:</p>
  
  <p><a href="https://i.stack.imgur.com/Zmy2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zmy2E.png" alt="enter image description here"></a></p>
  
  <p>I am learning MEAN with Angular2. I have following code in my server.js</p>
  
  <pre><code>const express = require('express');
  const path = require('path');
  const http = require('http');
  const bodyParser = require('body-parser');
  const mongoose = require('mongoose');
  const session = require('express-session');
  mongoose.connect("mongodb://localhost/demo");
  
  const api = require('../server/routes/api');
  
  const app = express();
  app.use(session({
      secret: 'somesecrettokenhere',
      name: 'demo',
      resave: false,
      saveUninitialized: true
  }));
  
  // Parsers for POST data
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  
  app.get('/', (req, res) =&gt; {
    res.sendFile(path.join(__dirname, '../dist/index.html'));
  });
  
  // Point static path to dist
      app.use(express.static(path.join(__dirname, '../dist')));
  
  // Set our api routes
      app.use('/routes', api);
  
  // Catch all other routes and return the index file
  app.get('*', (req, res) =&gt; {
      res.sendFile(path.join(__dirname, '../dist/index.html'));
  });
  
  /**
       * Get port from environment and store in Express.
   */
  const port = process.env.PORT || '3000';
  app.set('port', port);
  
  /**
       * Create HTTP server.
   */
  const server = http.createServer(app);
  
  /**
   * Listen on provided port, on all network interfaces.
   */
  server.listen(port, () =&gt; console.log(`API running on localhost:${port}`));
  </code></pre>
  
  <p>Below is my api.js:</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  
  router.post('/login', (req, res) =&gt; {
    console.log('Run');
  });
  
  module.exports = router;
  </code></pre>
  
  <p>Below is my Angular2 service.ts:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {Http, Response, Headers} from '@angular/http';
  import { Observable } from 'rxjs';
  import 'rxjs/add/operator/map';
  
  @Injectable()
  export class AuthService {
  
    constructor(private _http: Http) { }
  
        Login(email: string, password: string): Observable&lt;Response&gt; {
          let credentials = {
          _email: email,
          _password: password
        };
        return this._http.post('/api/login',{_uc:credentials}).map(
            (res: Response) =&gt; res.json()
        );
    }
  
  }
  </code></pre>
  
  <p><strong>Problem:</strong></p>
  
  <p>When I click on my form submit button it hits login method which is on my service.ts file but not show any error on server side console or not hitting my server api.js login post method. I don't know why my server side api.js Login post method is not hitting and not showing any error in console window. Please tell me what I'am doing wrong in my code. The client side code is working file I put console in my service.ts login method and its showing me output but http request is not working on server side. Please let me know if any other details has required in my question.</p>