Serving client-side DNode library - "cannot find module dnode/web"

481 Views Asked by At

I'm trying to build a simple bidirectional DNode app using the DNode tutorial here. However I'm not sure how to serve the client-side dnode js.

The example includes the following code:

var js = require('dnode/web').source();

var httpServer = http.createServer(function (req,res) {
    if (req.url == '/dnode.js') {
        res.writeHead(200, { 'Content-Type' : 'text/javascript' });
        res.end(js);
    }
//...

But the app won't run. I get: "Error: Cannot find module 'dnode/web'"

DNode is installed via npm. Any ideas?

2

There are 2 best solutions below

0
On BEST ANSWER

dnode/web is the really ancient way of hosting the source. Now /dnode.js is available by default so you can just <script src="/dnode.js"></script>.

0
On

Ran into the same thing, that article appears to be out of date. Go to dnode's page on Github and try the examples there instead. They work.