How to specify the desired address for the api?

Prompt, please, as to me working on the port 4200 to be able to obtain information via the api.
To immediately see the changes in real time.

api.js
const express = require('express');
const router = express.Router();

const model = require('../models/user');
//const axios = require('axios');


/* GET the api listing. */
router.get('/', (req, res) => {
 Res. send('api works');
});

// Get all posts
router.get('/users', (req, res) => {

model.find({})
.exec(function(err,users){
 if (err) throw err;
Res. json(users);
});


 // Get posts from the mock api
 //// This should ideally be replaced with a service that connects to MongoDB
//axios.get(`${API}/users`)
 // .then(posts => {
 // res.status(200).(json posts.data);
 // })
 // .catch(error => {
 // res.status(500).send(error)
 // });


});

module.exports = router;


users.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class UsersService {

 constructor(private http: Http) { }

 // Get all posts from the API
 getAllUsers() {
 return this.http.get('/api/users')
 .map(res => res.json());
}

}
June 14th 19 at 20:10
1 answer
June 14th 19 at 20:12
Balancing on the server such as nginx
and somehow this is wrong?

getAllUsers() {
return this.http.get('http//localhost:3000/api/users')
.map(res => res.json());
}

Angular app sends to 4200 - Trevion_Beer commented on June 14th 19 at 20:15
better not to tie the api of the port, but it is possible
I understand you need to smoke Doku http angular to bet your issue is seen often and there is more good advice, don't want to copy-paste - Wava_Berni commented on June 14th 19 at 20:18
Thank you! Viewing - Trevion_Beer commented on June 14th 19 at 20:21

Find more questions by tags AngularNode.js