Node.js をいじって、Twitter API リクエストを作成しようとしています。
私は Express で生成されたプロジェクトを使用しているので、そのようにapp.js
見えます
var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path')
, url = require('url');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
app.get('/', routes.index);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
そして、index.js
このような
exports.index = function(req, res){
var username = 'Axiol';
option = {
protocol: 'http:',
host: 'api.twitter.com',
pathname: '/1/statuses/user_timeline.json',
query: { screen_name: username, count: 10 }
}
var twitterUrl = url.format(options);
console.log(twitterUrl);
};
かなり問題ないようですが、常にこれらのエラーが返されます
ReferenceError: url is not defined
at exports.index (/Users/Arnaud/Sites/badge/routes/index.js:17:20)
at callbacks (/Users/Arnaud/Sites/badge/node_modules/express/lib/router/index.js:161:37)
at param (/Users/Arnaud/Sites/badge/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/Arnaud/Sites/badge/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/Users/Arnaud/Sites/badge/node_modules/express/lib/router/index.js:170:5)
at Object.router (/Users/Arnaud/Sites/badge/node_modules/express/lib/router/index.js:33:10)
at next (/Users/Arnaud/Sites/badge/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.methodOverride [as handle] (/Users/Arnaud/Sites/badge/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:37:5)
at next (/Users/Arnaud/Sites/badge/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at multipart (/Users/Arnaud/Sites/badge/node_modules/express/node_modules/connect/lib/middleware/multipart.js:64:37)
が見つからないように見えますが、 ...url
で明確に定義されています。app.js
何か案が ?