• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript CORS/Express: Getting data from server from domain html


New Coder

This has been many days of trying to research however, either I am misunderstanding something or the solution online is not directred toward my issue.

I am running a node server on a sub-domain as such: xxx.yyy.com

I have express, socket.io and cors all installed.

My app.js file:

const http = require('http');
const express = require('express');
const app = express();
const cors = require('cors');
const server = require('http').createServer(app);

const path = require('path');

const io = require("socket.io")(server);


app.use('/', express.static(path.join(__dirname, 'public')));

io.on("connection", (socket) => {


In my public folder I have a file 'testCors.html' which just outputs, Hello World.

Outside of the server, I have a file located here: www.yyy.com/testCors.php

<script src="_js/jquery-3.6.0.min.js"></script>

$( document ).ready(function() {

                type: "GET",
                url: 'https://xxx.yyy.com/testCors.html',
                dataType: "html",
                success: function(result) {


As you can see, I just want the yyy.com/testCors.php page to alert 'Hello World' as found from xxx.yyy.com/textCors.html

However, I continue to get the CORS error.

Any related issues I can find online on stackoverflow, YT and here and other forums seems to talk about one port on localhost to another port, or receiving API from external domain, however I want my php page on public_html to receive.

I have also tried setting headers with PHP on client side but not having any luck with that either.

Any guidance will be greatly appreciated!