How to serve static file using Restify

I am working with a node application, where I need to serve static files(js,css).

My project structure is like below:

-Projectroot
     -restifyServer
         -server.js
     -frontEnd
         -index.html
         -js
         -partials
         -css

server.js is not only the server it serves XML also.

Also for serving index.html I have routing like below:

server.get('/', getIndexhtml);

And getIndexhtml callback is like:

var getIndexhtml = function indexHTML(req, res, next) {
    fs.readFile(__dirname + '/../frontendapp/index.html', function (err, data) {
        if (err) {
            next(err);
            return;
        }
        res.setHeader('Content-Type', 'text/html');
        res.writeHead(200);
        res.end(data);
        next();
});
}

When I start server and navigate my browser to 'http://localhost:8080/' it loads html without static files.

In console I get error like below:

http://localhost:8080/js/library/jquery.js 404 (Not Found)

How can I configure resitfy to serve static files. I have tried this solution but couldn't make it work.

Thanks in advance.

You didn't serve other static files such as: "js/library/jquery.js". I highly recommend using express framework instead , it's easy for serving static files without doing it manually.

What about having an Apache server for your static site? That way you won't have to write all through restify.

Just have your restify server to serve the xml you need (the way you are doing it), and have all your client-side html, css, js files in apache.