Access-Control-Allow-Origin on node.js WITHOUT Express.js

To solve error 'No Access-Control-Allow-Origin'

So I tried to search for Access-Control-Allow-Origin for Node.js, but I could only see those using Express.js api.

The warning looks like very simple: add header 'Access-Control-Allow-Origin' to the response.

Origin http://localhost is not allowed by Access-Control-Allow-Origin

Like the question above, I could also see many answers have app.use or res.header but:

  1. I don't know where the app. comes from
  2. res.header doesn't work for

    http.createServer(function (req, res){ "Something" });

Also, I tried

res.writeHead(200, {'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/html','Content-Length':data.length});

But doesn't work.

I know this problem can be solved on the client side, like security off option for chrome or add on. But I want my server gives service on any client so that the users don't need to do any setting on it.

You should read the manual:

HTTP Node.js v0.10.30 Manual & Documentation

http.createServer(function (req, res) {
    res.setHeader("Access-Control-Allow-Origin", "*");
});

Sidenote: app is mostly coming from var app = express(); I guess.