Token in header (cURL) with Express.js Node.js

So, I want to use this code in my project:

var allowCrossTokenHeader = function(req, res, next) {
    res.header("Access-Control-Allow-Headers", "token");
};

But it does not work, the server hangs and does not work, if I comment this code the server is working correctly. I need to check a token in each request to my RESTful api, any idea how to do?

You need to call next() for it to continue to the next middleware in the stack.

var allowCrossTokenHeader = function(req, res, next) {
    res.header("Access-Control-Allow-Headers", "token");
    next();
};

If the current middleware does not end the request-response cycle, it must call next() to pass control to the next middleware, otherwise the request will be left hanging.

Documentation