NodeExpress服务器请求返回HTTP ERROR 403授权拒绝问题求助
Hey there, let's break down why you're hitting that 403 "access denied" error even after setting up CORS correctly. Here are the most likely fixes to try:
1. 特权端口权限不足
Port 80 is a privileged system port—regular user accounts don’t have permission to bind to it on most operating systems. That means your Express server might not actually be starting up properly, which leads to the 403 error when you try to access it.
- On Linux/macOS: Run your server with admin privileges using
sudo node your-server-file.js - On Windows: Open Command Prompt or PowerShell as Administrator first, then run your server command
2. Port 80 is already in use
Another common issue: Some other service (like Apache, Nginx, or even a random background app) might be using port 80 already. To check:
- Windows: Run
netstat -ano | findstr ":80"in Command Prompt to see what’s using the port - Linux/macOS: Run
lsof -i :80in Terminal
If something’s occupying port 80, either shut that service down, or switch your Express server to a non-privileged port (like 3000, 8080) which doesn’t require special permissions. Here’s a quick modified version of your code to test this:
var express = require('express') var cors = require('cors') var app = express() app.use(cors()) app.get('/', function (req, res, next) { res.json({msg: 'This is CORS-enabled for all origins!'}) }) // Switch to port 3000 instead of 80 app.listen(3000, function () { console.log('CORS-enabled web server listening on port 3000') })
After changing the port, access localhost:3000 in your browser or Postman—this should work without permission issues.
3. Firewall or security software is blocking the request
Your local firewall, antivirus, or even a network security tool might be blocking incoming requests to port 80. Try temporarily disabling these tools (just for testing!) to see if the error goes away. If it does, add an exception rule to allow your Node.js process to use port 80.
4. Verify your server is actually running
Double-check your console output after starting the server. If you don’t see the message CORS-enabled web server listening on port 80, that means the server failed to start—this almost always ties back to port permissions or an occupied port.
内容的提问来源于stack exchange,提问作者Yusuf

