First idea:
var Post = ....;
var Stat = ....;
....
app.get("/view/:nid", function (req, res) { Stat.view(req,res,Post); });
But I'm a bit confused (bad English here too ;-)
You don't use
exports.module = {
view: view
}
but instead, you mentionted
exports.module = function view() ....
It's not the same.
Angel "Java" Lopez
@ajlopez
On Tue, Feb 25, 2014 at 1:18 PM, Ziobudda <[email protected]> wrote:
> Hi Kevin, I have not understand how to pass "req" and "res" variable to my
> module.
> For post I have understand that I can do in this way:
>
> ...
> var Post = mongoose.model('Articoli');
> View.Post = Post;
> ....
>
> But for req and res ?
>
> Thanks again.
>
> M.
>
> ------------------------------
> Da: Kevin Ingwersen Kevin Ingwersen <[email protected]>
> Rispondi: [email protected] [email protected]
> Data: 25 febbraio 2014 at 17:01:40
> A: [email protected] [email protected]
> Oggetto: Re: [nodejs] Module: how to pass variable ?
>
> Hey.
>
> Consider adding this to your module:
>
> module.exports.view = function...
> module.exports.Post={};
>
> Now, you can modify the second Post variable with...
>
> var View = require(...);
> View.Post={dat:"dude"};
>
> Should help.
>
> Otherwise, you may use the globals object - its global everywhere, and the
> same everywhere. So if yo use:
>
> global.my_Post={dat:"dude"};
>
> You can do the same in your module with:
>
> console.log("Dat", global.my_Post.dat);
>
> Hope it helps in a way. ^^
>
> Kind regards, Ingwie
> Am Di. Feb. 25 2014 16:44:55 schrieb Ziobudda:
>
> Hi all, In my nodes app (nodejs+express+jade) I want use module to
> manage a route.
>
> In my code I have these lines (only the important ones):
>
> var express = require('express');
> var routes = require('./routes');
> var Stats = require("./routes/view_stat.js");
> var mongoose = require('mongoose');
> var db = mongoose.connect('mongodb://localhost/articoli');
>
> var Schema = mongoose.Schema;
> var Articoli = new Schema({
> .....
> });
>
> mongoose.model('Articoli', Articoli);
> var Post = mongoose.model('Articoli');
>
> app.get('/view/:nid', Stats.view);
>
> Now, in my Stats.view function (inside view_stats.js file) I need to
> "pass": req, res and Post.
>
> A code like this one (tell me if there is an error):
>
> module.exports = function view(req,res,Post) {
>
> res.render('stats', { 'nid' : req.params.nid });
> };
>
>
> But how can I "pass" these variables to my module ?
>
> Thanks and sorry for my bad english.
>
> M.
> --
> Michel 'ZioBudda' Morelli [email protected]
> Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
> Telefono: 0200619074
> Mobile: +39-3939890025 -- Fax: +39-0291390660
>
> http://www.ziobudda.net Skype: zio_budda
> http://www.ziobuddalabs.it Twitter: ziobudda
>
> --
>
>
>
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> 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 post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> Michel 'ZioBudda' Morelli [email protected]
> Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
> Telefono: 0200619074
> Mobile: +39-3939890025 -- Fax: +39-0291390660
>
> http://www.ziobudda.net Skype: zio_budda
> http://www.ziobuddalabs.it Twitter: ziobudda
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> 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 post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
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].
For more options, visit https://groups.google.com/groups/opt_out.