localhost:3000 doesn't change when switching node.js apps

When I was running a new node.js app (call this app 2), something weird(read:something that I don't understand) happened: I tried running app 2 after I had been working on another app (app1) earlier during the day. For the app before, I had something in the code that automatically redirected the localhost:3000 to a specific site. I stopped running that app earlier in the day though.

When I tried running the new app2 that also used the port 3000 with localhost, it still automatically redirected even though the previous app that redirected clearly wasn't running.

app1 was using express.js. app2 was not. If anyone thinks any specific code would help, I'd be more than happy to provide, though I don't know where to look because it seems I had standard code that would just redirect localhost:3000 and had code that redirected some other generic sites. facebook.com was edited in my hostfile to go to my localhost ip address. Here is some of it:

app.get('*',function(req,res){
    console.log(req.get('host')+req.originalUrl);
    if(req.get('host')+req.originalUrl == "facebook.com:3000/"){
        res.redirect(301,'https://github.com');
    }
    else{
        res.redirect(301,'https://google');
    }
});

...

app.listen(app.get('port'), function() {
  console.log("✔ Express server listening on port %d in %s mode", app.get('port'), app.settings.env);
});

So when running the new app, I was spooked why it would still redirect.

Additionally, localhost:3000 only worked for my new app when I changed the code in the new app to redirect to port 4000 and then changed it back to 3000 after it worked with 4000.

If anyone has any idea why this is, please let me know!

Thanks.

You're doing a 301 redirect. This is a permanent redirect. Browsers, proxies, and everything else, can cache this indefinitely.

Consider a 302 or 307.