Mark Nguyen
Mark Nguyen

Reputation: 7448

Access file on a Node.js server

If you are familiar with NowJS, one you start an instance of Now on the server, you can access a file located on the server by <script src="http://localhost:8080/nowjs/now.js"></script>

Any ideas on how to implement this?

Thanks, Mark

Upvotes: 0

Views: 1727

Answers (1)

T W
T W

Reputation: 6317

There are many static file handler modules already in node, take a look at: https://github.com/joyent/node/wiki/modules#wiki-web-frameworks-static

Most popular are: https://github.com/felixge/node-paperboy and https://github.com/cloudhead/node-static

Using node static is as simple as:

var static = require('node-static');
var file = new(static.Server)('./public');

    require('http').createServer(function (request, response) {
        request.addListener('end', function () {

            file.serve(request, response);
        });
    }).listen(8080);

Upvotes: 2

Related Questions