it's works well Thanks Ema
Le samedi 19 mars 2016 18:20:01 UTC+1, Emanuele DelBono a écrit : > > connection is defined in main.js not in match.js > Modules isolate the scope of the variables. > Since match.js exports a function you can pass the connection to the > function. > > On Sat, Mar 19, 2016 at 11:16 AM, jeg <[email protected] <javascript:>> > wrote: > >> Hi all, >> >> error message when match.js is called with insert >> >> thanks >> >> Eric >> >> match.js:53 >> connection.query('insert into MYTABLE set ' + wREQUEST, >> function(err, res) { >> ^ >> >> ReferenceError: connection is not defined >> >> >> *** >> main.js >> >> var request = require('request'); >> var cheerio = require('cheerio'); >> >> var mysql = require('mysql'); >> var connection = mysql.createConnection({ >> host : 'localhost', >> user : 'admin', >> password : 'secret', >> database : 'mydb' >> }); >> >> connection.connect(); >> >> request('http://url/en', function (error, response, html) { >> if (!error && response.statusCode == 200) { >> var $ = cheerio.load(html); >> $('div.expander-button').each(function(i, element){ >> var a = $(this); >> var zurl = a.next().children().children().attr('href'); >> // Our parsed meta data object >> var metadata = { >> url: zurl >> }; >> //console.log(zurl); >> var a = require('./match')(zurl); >> a.extractValue(); >> }); >> } >> }); >> >> connection.end(); >> >> >> >> *** >> match.js >> >> module.exports = function(zurl) { >> return { >> extractValue: function() { >> .... >> .... >> .... >> >> >> connection.query('insert into MYTABLE set ' + wREQUEST, function(err, >> res) { >> if (err) throw err; >> } ) ; >> >> >> -- >> Job board: http://jobs.nodejs.org/ >> New group rules: >> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >> Old group rules: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> --- >> You received this message because you are subscribed to the Google Groups >> "nodejs" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/nodejs/38690d8e-9440-4cbd-bcf3-3b72e892eb98%40googlegroups.com >> >> <https://groups.google.com/d/msgid/nodejs/38690d8e-9440-4cbd-bcf3-3b72e892eb98%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > ema > http://ema.codiceplastico.com <http://blog.codiceplastico.com/ema> > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/d2e79ed9-1d4f-4674-9051-fb4253f8e019%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
