node_chat's fu module

73 views
Skip to first unread message

Scott González

unread,
Mar 19, 2010, 10:22:04 AM3/19/10
to nod...@googlegroups.com
Is the fu module used in node_chat something that was custom written specifically for the chat demo or is it actually maintained as a module somewhere? I'm wondering because I'd like to change it so that it can be used to create multiple http servers.

Current API:

var fu = require("./fu");
fu.get(url, callback);
fu.listen(port);

Proposed API:

var fu = require("./fu");
var server = fu.createServer();
server.get(url, callback);
server.listen(port);

Tim Caswell

unread,
Mar 19, 2010, 10:35:16 AM3/19/10
to nodejs
creationix/node-router is based on fu.js, but makes it a little easier
to use for real apps. As far as I know, fu.js was just written by
Ryan for the chat demo and isn't used for anything else.

Scott González

unread,
Mar 19, 2010, 11:03:37 AM3/19/10
to nod...@googlegroups.com
Thanks Tim. So the idea is to just require the module each time you want to create a new server?

var server1 = require("./node-router");
var server2 = require("./node-router");

vs.

var router = require("./node-router");
var server1 = router.createServer();
var server2 = router.createServer();


--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.


Tim Caswell

unread,
Mar 19, 2010, 11:50:40 AM3/19/10
to nodejs
I'm not sure about that. I think require does some caching (or at
least it should). It wouldn't be hard to modify node-router to fit
the second case though.

> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>

Scott González

unread,
Mar 19, 2010, 12:25:47 PM3/19/10
to nod...@googlegroups.com
On Fri, Mar 19, 2010 at 11:50 AM, Tim Caswell <t...@creationix.com> wrote:
I'm not sure about that. I think require does some caching (or at
least it should).  It wouldn't be hard to modify node-router to fit
the second case though.

Okay, I can fork it to add in .createServer() then. I'll use this for the conversion of the node_chat demo to a chat module.

MilesTogoe

unread,
Mar 19, 2010, 2:08:45 PM3/19/10
to nod...@googlegroups.com
On 03/19/2010 08:50 AM, Tim Caswell wrote:
> I'm not sure about that. I think require does some caching (or at
> least it should). It wouldn't be hard to modify node-router to fit
> the second case though.
>

looks really interesting - we are looking at node-router for a very
straight forward sinatra like controller w/o the extra bells and
whistles coming with Express (we don't need/want flash or haml, or sass,
...) but didn't see any info whether node-router has a "redirect"
(something we do use a lot) - if not, we'll use Express

at the moment our stack looks like:
node.js
node-router
json-template
mongo-native

Scott González

unread,
Mar 19, 2010, 2:13:44 PM3/19/10
to nod...@googlegroups.com
On Fri, Mar 19, 2010 at 2:08 PM, MilesTogoe <miles...@gmail.com> wrote:
looks really interesting - we are looking at node-router for a very straight forward sinatra like controller w/o the extra bells and whistles coming with Express (we don't need/want flash or haml, or sass, ...)   but didn't see any info whether node-router has a "redirect" (something we do use a lot) - if not, we'll use Express

Adding a redirect method should be pretty straight-forward, even an internal redirect to avoid the network overhead.

Ciaran

unread,
Mar 19, 2010, 2:59:32 PM3/19/10
to nod...@googlegroups.com
Fwiw haml sass, flash plugins etc. are all optional, it would be dead
easy to provide a json-template view in express :)
- cj

On Friday, March 19, 2010, MilesTogoe <miles...@gmail.com> wrote:
> On 03/19/2010 08:50 AM, Tim Caswell wrote:
>
> I'm not sure about that. I think require does some caching (or at
> least it should).  It wouldn't be hard to modify node-router to fit
> the second case though.
>
>
>
> looks really interesting - we are looking at node-router for a very straight forward sinatra like controller w/o the extra bells and whistles coming with Express (we don't need/want flash or haml, or sass, ...)   but didn't see any info whether node-router has a "redirect" (something we do use a lot) - if not, we'll use Express
>
> at the moment our stack looks like:
> node.js
> node-router
> json-template
> mongo-native
>
>
>
>
>

> On Mar 19, 11:03 am, Scott González<scott.gonza...@gmail.com>  wrote:


>
>
> Thanks Tim. So the idea is to just require the module each time you want to
> create a new server?
>
> var server1 = require("./node-router");
> var server2 = require("./node-router");
>
> vs.
>
> var router = require("./node-router");
> var server1 = router.createServer();
> var server2 = router.createServer();
>
>
>
> On Fri, Mar 19, 2010 at 10:35 AM, Tim Caswell<t...@creationix.com>  wrote:
>
>
> creationix/node-router is based on fu.js, but makes it a little easier
> to use for real apps.  As far as I know, fu.js was just written by
> Ryan for the chat demo and isn't used for anything else.
>
>
>
>

> On Mar 19, 10:22 am, Scott González<scott.gonza...@gmail.com>  wrote:

> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.

Anders Hellerup Madsen

unread,
Mar 19, 2010, 3:31:13 PM3/19/10
to nod...@googlegroups.com

On Mar 19, 2010, at 7:08 PM, MilesTogoe wrote:

looks really interesting - we are looking at node-router for a very straight forward sinatra like controller w/o the extra bells and whistles coming with Express (we don't need/want flash or haml, or sass, ...)   but didn't see any info whether node-router has a "redirect" (something we do use a lot) - if not, we'll use Express


You could also look at Simon Willisons djangode - it provides exactly that, a simple url routing scheme and a redirect helper.


(It also includes a port of the django template system, which I have done, but you don't have to use that - it's all completely separate modules.


Tim Caswell

unread,
Mar 19, 2010, 3:42:17 PM3/19/10
to nodejs
What kind of redirect are you looking for. It's really just a simple
5 line (braces and all) addition to the code in most cases.

On Mar 19, 2:13 pm, Scott González <scott.gonza...@gmail.com> wrote:

MilesTogoe

unread,
Mar 19, 2010, 4:30:50 PM3/19/10
to nod...@googlegroups.com
Tim Caswell wrote:
> What kind of redirect are you looking for. It's really just a simple
> 5 line (braces and all) addition to the code in most cases.
>
didn't know there were various kinds - basically just a "redirect
('/foo')" kind

it probably doesnt' matter much whether we use node-router or express -
it seems node-router is just a simple js lib to add, for express we need
to use pkg mgmt or run within it's folder, on the other hand, express
might be a bit simpler w/o regex, etc

either way we're attracted to the all js approach over using ruby.

Aaron Heckmann

unread,
Mar 19, 2010, 4:36:29 PM3/19/10
to nod...@googlegroups.com
Here's the Getting Started with Express: http://wiki.github.com/visionmedia/express/get-started

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.




--
Aaron

Tim Caswell

unread,
Mar 19, 2010, 5:07:18 PM3/19/10
to nodejs

On Mar 19, 4:30 pm, MilesTogoe <miles.to...@gmail.com> wrote:
> Tim Caswell wrote:
> > What kind of redirect are you looking for.  It's really just a simple
> > 5 line (braces and all) addition to the code in most cases.
>
> didn't know there were various kinds - basically just a "redirect
> ('/foo')" kind


The two main kinds are an HTTP redirect and an internal redirect.
With an HTTP redirect node has to return a 302 or 301 message with the
new location and the browser has to make a new request with the new
url. The url in the browser gets physically changed. With an
internal redirect, you just change internal state in the node server
to pretend that the request really came from another url and respond
as if that was the case. The browser url doesn't get changed in this
case and a second request is not needed.

MilesTogoe

unread,
Mar 19, 2010, 6:29:44 PM3/19/10
to nod...@googlegroups.com
On 03/19/2010 02:07 PM, Tim Caswell wrote:
>
> On Mar 19, 4:30 pm, MilesTogoe<miles.to...@gmail.com> wrote:
>
>> Tim Caswell wrote:
>>
>>> What kind of redirect are you looking for. It's really just a simple
>>> 5 line (braces and all) addition to the code in most cases.
>>>
>> didn't know there were various kinds - basically just a "redirect
>> ('/foo')" kind
>>
>
> The two main kinds are an HTTP redirect and an internal redirect.
> With an HTTP redirect node has to return a 302 or 301 message with the
> new location and the browser has to make a new request with the new
> url. The url in the browser gets physically changed. With an
> internal redirect, you just change internal state in the node server
> to pretend that the request really came from another url and respond
> as if that was the case. The browser url doesn't get changed in this
> case and a second request is not needed.
>

oh yeah, I wasn't thinking of the http redirect - rather, just the
internal one.

next step is integrating with json-template and best way to pass vars to
the template - working with that now.


Reply all
Reply to author
Forward
0 new messages