Good day. There was a problem driving me crazy. It's the second day I've been fighting over her. There are two files, app.js and api.js.

// app.js

const app = require('express')(); const proxy = require('express-http-proxy'); app.use('/api', proxy('http://localhost:8888')); app.use((err, req, res, next) => { console.log(err.message); }); 

//api.js

 const app = require('express')(); const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/bookshop'); var Users = require('./models/users'); 

and further appeal to the routes ...

At the end of api.js, it is indicated that this script is listened on port 8888:

 app.listen(8888, err => { if (err) console.log(err); console.log('worked on http://localhost:8888'); }); 

inside api.js there should be an appeal to the routes and to the database, but the matter still doesn’t come to the address, because when I access the site I get the following:

 "connect ECONNREFUSED 127.0.0.1:8888" 

This message returns this middleware from app.js:

 app.use((err, req, res, next) => { console.log(err.message); }); 

In package.json in "scripts" I indicated that the app.js server (3000 port) and api.js server (port 8888) would also be launched, but when you refresh the page on the site, the site is addressed to localhost: 3000 / api / users not localhost: 8888 / api / users

Help defeat this attack! There are no forces anymore, the entire Internet has broken out, but there was no solution to the problem.

Shl on a working computer, this code works fine, but at home flatly refuses. At work x32 windows 8.1, at home x64 windows 8.1, if this is important.

  • What does netstat -a | findstr LISTEN tell you netstat -a | findstr LISTEN netstat -a | findstr LISTEN ? - Geslot
  • image link: ibb.co/bKyjRk - Andrey Markov
  • I wanted to add that if you run the scripts separately, i.e. call node app.js in one terminal and node api.js in the second, then everything works fine - Andrey Markov

0