Mac OS X NodeJS: has no method 'router' error

后端 未结 3 1636
既然无缘
既然无缘 2021-01-15 01:14

Installed NodeJS v0.6.12 on MAC OS X using Mac Ports.

    win764:node iwaldman$ which node
         /opt/local/bin/node

    win764:node iwaldman$ node -v
         


        
3条回答
  •  天涯浪人
    2021-01-15 01:43

    Install express and slightly rewrite the code:

    var express = require('express');
    var util    = require('util');
    
    function sendjson(res,obj)
    {
        res.writeHead(200, {
            'Content-Type': 'application/json',
        });
    
        var objstr = JSON.stringify(obj);
        util.debug('SENDJSON:' + objstr);
        res.end(objstr);
    }
    
    
    var app = express();
    
    app.get('/foo', function(req,res) {
        sendjson(res, {path:'/foo'});
    });
    
    app.get('/bar', function(req,res) {
        sendjson(res, {path:'/bar'});
    });
    
    app.listen(3000);
    util.debug('Server running at http://127.0.0.1:3000');
    

提交回复
热议问题