Noob Question

61 views
Skip to first unread message

Sammaye

unread,
Jul 7, 2010, 7:24:22 AM7/7/10
to Express
Hi Everyone,

I'm an absolute noob to both node.js and express however have been
getting to crips and have formed a bit of a kool app however I do have
one little problem.

I am not using my node.js server directly I am accessing it through
JQuery on a Nginx server and I access it like so
"129.129.129.393:8124/?username=sam&someotherpoo=this".

It is with complicated urls like this that I start to get a problem. I
can do "/sam/this" but then I get problems with defineing the url
within the code and how express gets the url.

My current understanding is:

get(/:user/:something,function()

would get me /sam/this out of the url but how can I use proper gets
within a url that I can uniquely identify?

I mean what happens if I have another url that needs to be /post/this
and would have the same structure within the express code as the /sam/
this url?

Really what im looking for is a way to put a top level router that can
grab the url in it's raw form and operate on it to clean it up and
shove it to it's correct path. I am however unsure if that can be done
and I have to use /sam/this style urls. I know this sounds kinda weird
and probably I ain't explained it well but hopefully you'll understand
what I'm trying to do.

Also is there a api documentation for express anywhere all I see if
basic stuff I don't see a method by method/function documentation of
the framework?

thanks,

Aaron Heckmann

unread,
Jul 7, 2010, 7:40:20 AM7/7/10
to expre...@googlegroups.com
http://wiki.github.com/visionmedia/express/routing

Not sure I understand. What do you mean by " but how can I use proper gets

within a url that I can uniquely identify?"

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




--
Aaron
http://clickdummy.net

Sammaye

unread,
Jul 7, 2010, 7:59:52 AM7/7/10
to Express
Ah yes I understand now.

I was worried about duplicate urls originally but after reading that
page it seems as though I've got more options than I originally
thought with URLs :)

Basically I am used to defining seperate functions in i.e. server side
with normal url paths decoded from url rewrites (so /post/1 becomes
post.php?id=1) and I was worried about trying to decode my urls so I
didn't get ambiquity within my app but everything seems fine after
ready that page now.

Do you know if theres a clear outline of all functions (api
documentation)? Both the wiki and the main website do not outline
every function though they do hold some very interesting information.

Thanks,

On Jul 7, 12:40 pm, Aaron Heckmann <aaron.heckm...@gmail.com> wrote:
> http://wiki.github.com/visionmedia/express/routing
> > express-js+...@googlegroups.com<express-js%2Bunsu...@googlegroups.com>
> > .

Aaron Heckmann

unread,
Jul 7, 2010, 8:53:07 AM7/7/10
to expre...@googlegroups.com
There isn't more documentation :( , just the code itself which is
documented well. The project also contains specs and examples between
which should provide a big help too.

> express-js+...@googlegroups.com.

Dennis Blöte

unread,
Jul 7, 2010, 9:26:17 AM7/7/10
to expre...@googlegroups.com
Hello everyone,

> There isn't more documentation :(

I'm currently working on a project that uses some of the undocumented features/plugins of express (i.e. flash, cookie, session, hooks) and I am looking forward to add documentation for these when I got the project out the door, because I had a hard time finding out how to get things running by looking through the express codebase (though it wasn't impossible ;)).

I hope I can publish some code examples rather sooner than later (maybe by the end of the next week).

Best regards,
Dennis

Aaron Heckmann

unread,
Jul 7, 2010, 9:37:33 AM7/7/10
to expre...@googlegroups.com
That's great Dennis!

Sammaye

unread,
Jul 7, 2010, 9:41:55 AM7/7/10
to Express
That is awesome. I'm getting the jist of the framework now and I had
to learn thrift for cassandra so it's not that bad. Just in case you
havent installed thrift before it's documentation is install
instructions (which didn't work for me so I had install it
manually).....and that's it!!!

Though don't put the code as white text on dark background and very
wordy like node.js, their documentation hurts my eyes and fatigues me
easily :(.

On Jul 7, 2:26 pm, Dennis Blöte <m...@dennisbloete.de> wrote:
> Hello everyone,
>
> > There isn't more documentation :(
>
> I'm currently working on a project that uses some of the undocumented features/plugins of express (i.e. flash, cookie, session, hooks) and I am looking forward to add documentation for these when I got the project out the door, because I had a hard time finding out how to get things running by looking through the express codebase (though it wasn't impossible ;)).
>
> I hope I can publish some code examples rather sooner than later (maybe by the end of the next week).
>
>   Best regards,
>   Dennis
>
> Am 07.07.2010 um 14:53 schrieb Aaron Heckmann:
>
> > There isn't more documentation :( , just the code itself which is
> > documented well. The project also contains specs and examples between
> > which should provide a big help too.
>

vision media [ Tj Holowaychuk ]

unread,
Jul 7, 2010, 10:07:24 AM7/7/10
to expre...@googlegroups.com
1.0 will have better docs :) I am making sure if this lol more / better docs. I will be removing the old
site and replacing it, along with removing the wiki pages, and clearing out all the issues
Tj Holowaychuk
Vision Media
President & Creative Lead

Dennis Blöte

unread,
Jul 7, 2010, 10:12:58 AM7/7/10
to expre...@googlegroups.com
@TJ When do you plan to release 1.0? As I said I'd like to help with the documentation, in this case I'll wait for 1.0 and see what's missing when you publish the new site.

vision media [ Tj Holowaychuk ]

unread,
Jul 7, 2010, 10:33:48 AM7/7/10
to expre...@googlegroups.com
Hopefully late next week. The site / man pages will be generated from markdown in the master branch so it will
be easier for contributors as well :)

Josef Salyer

unread,
Jul 7, 2010, 10:57:36 AM7/7/10
to expre...@googlegroups.com
awesome!! Looking forward to the new version!

Sammaye

unread,
Jul 8, 2010, 4:09:00 AM7/8/10
to Express
Yet another question :)

Does SSJS or specifically node have strong inheritance.

I have two files:

app.js
session.js

Within my app.js I include a mongo db class but I use it within
session.js.

Both are required into app.js like:

var mongo = require("mongo"),
session = require("session");

Can SSJS detect that session should have access to the same namespace
as app.js or do I need to make the mongo object again within the
session class?

On Jul 7, 3:57 pm, Josef Salyer <josef.sal...@gmail.com> wrote:
> awesome!!  Looking forward to the new version!
>
> On Wed, Jul 7, 2010 at 8:33 AM, vision media [ Tj Holowaychuk ]
>
> <t...@vision-media.ca> wrote:
> > Hopefully late next week. The site / man pages will be generated from
> > markdown in the master branch so it will
> > be easier for contributors as well :)
>
> > On Wed, Jul 7, 2010 at 7:12 AM, Dennis Blöte <m...@dennisbloete.de> wrote:
>
> >> @TJ When do you plan to release 1.0? As I said I'd like to help with the
> >> documentation, in this case I'll wait for 1.0 and see what's missing when
> >> you publish the new site.
>
> >> Am 07.07.2010 um 16:07 schrieb vision media [ Tj Holowaychuk ]:
>
> >> > 1.0 will have better docs :) I am making sure if this lol more / better
> >> > docs. I will be removing the old
> >> > site and replacing it, along with removing the wiki pages, and clearing
> >> > out all the issues
>

Sam Millman

unread,
Jul 8, 2010, 7:05:40 AM7/8/10
to Express
And again,

how can I get an object of the response?

I can do this.whatever for request but if I want to do response.setCookies() what would I do for that?

I do notice in the examples that this context can also be used to set the content type within reponse headers? can this context be used to access response methods like response.setCookies?
Bow Chicka Bow Wow

Ciaran

unread,
Jul 8, 2010, 7:07:42 AM7/8/10
to expre...@googlegroups.com
inside a route 'this' refers to the request object, the request object
contains a property 'response' so:

so this.response.setCookie() etc.

Does that help?

-cj.

Sam Millman

unread,
Jul 8, 2010, 7:08:54 AM7/8/10
to expre...@googlegroups.com
Ah yes that does it thanks :)

Sammaye

unread,
Jul 10, 2010, 2:50:10 PM7/10/10
to Express
I got yet another problem.

I've been looking through the doc and that but I still cannot seem to
get cookies to work.

I have got this:

require("express/plugins");

configure(function(){
use(MethodOverride);
use(Cookie);
use(ContentLength);
set('root', __dirname);
});

this.cookie("sx");
this.cookie("sx", "sx", opts);

But node.js just returns an error for either of the this.cookie lines.
I cannot seem to get my head around how to use the cookie extension. I
look through the docs and even the code to no avail.

According to the code that line should work but it doesn't.

On Jul 8, 12:08 pm, Sam Millman <smill...@nhbs.co.uk> wrote:
> Ah yes that does it thanks :)
>
> On 8 July 2010 12:07, Ciaran <ciar...@gmail.com> wrote:
>
> > inside a route 'this' refers to the request object, the request object
> > contains a property 'response' so:
>
> > so this.response.setCookie() etc.
>
> > Does that help?
>
> > -cj.
>
> > On Thu, Jul 8, 2010 at 12:05 PM, Sam Millman <sam.mill...@gmail.com>
> > wrote:
> > > And again,
>
> > > how can I get an object of the response?
>
> > > I can do this.whatever for request but if I want to do
> > response.setCookies()
> > > what would I do for that?
>
> > > I do notice in the examples that this context can also be used to set the
> > > content type within reponse headers? can this context be used to access
> > > response methods like response.setCookies?
>
> > <express-js%2Bunsu...@googlegroups.com<express-js%252Buns...@googlegroups.com>
>
> > >> > >> > > >>>> .
> > >> > >> > > >>>> For more options, visit this group at
> > >> > >> > > >>>>http://groups.google.com/group/express-js?hl=en.
>
> > >> > >> > > >>> --
> > >> > >> > > >>> Aaronhttp://clickdummy.net
>
> > >> > >> > > >> --
> > >> > >> > > >> You received this message because you are subscribed to the
> > >> > >> > > >> Google
> > >> > >> > > >> Groups
> > >> > >> > > >> "Express" group.
> > >> > >> > > >> To post to this group, send email to
> > >> > >> > > >> expre...@googlegroups.com.
> > >> > >> > > >> To unsubscribe from this group, send email to
> > >> > >> > > >> express-js+...@googlegroups.com<express-js%2Bunsu...@googlegroups.com>
> > .
> > >> > >> > > >> For more options, visit this group at
> > >> > >> > > >>http://groups.google.com/group/express-js?hl=en.
>
> ...
>
> read more »

Aaron Heckmann

unread,
Jul 10, 2010, 4:43:32 PM7/10/10
to expre...@googlegroups.com
you just need to call `this.cookie` inside of a route:

get("/", function(){
  this.cookie("totallyworks!")
})


To unsubscribe from this group, send email to express-js+...@googlegroups.com.

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

Sammaye

unread,
Jul 10, 2010, 4:52:15 PM7/10/10
to Express
Ahhh lol cheers.

On Jul 10, 9:43 pm, Aaron Heckmann <aaron.heckm...@gmail.com> wrote:
> you just need to call `this.cookie` inside of a route:
>
> get("/", function(){
>   this.cookie("totallyworks!")
>
> })
> ...
>
> read more »
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Sammaye

unread,
Jul 13, 2010, 8:03:04 AM7/13/10
to Express
How can I attach a function to run on response in express?

so I want saveSession to run when response begins, basically at the
end of the script.

Is there an easy way of doing this?

I know the built in session class does this but I can't use that since
my sessions are quite customised and need some special functions and
behaviour that meant writing a new class was easier.
> ...
>
> read more »

vision media [ Tj Holowaychuk ]

unread,
Jul 13, 2010, 10:26:28 AM7/13/10
to expre...@googlegroups.com
1.0 will use Connect's session api, http://github.com/extjs/Connect :)
if you check the wiki I also have a Redis store available

> ...
>
> read more »

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




--

Sam Millman

unread,
Jul 13, 2010, 10:29:51 AM7/13/10
to expre...@googlegroups.com
Thanks that look kool, though my problem is that I cant return from the session class to the app like respond a message "your session id dont match" since my session handler for node.js works ontop of php and should never create sessions. If there is a way I can respond from the session plugin class that would be awesome otherwise running on response is my only choice :(.
Bow Chicka Bow Wow

Sam Millman

unread,
Jul 13, 2010, 10:50:06 AM7/13/10
to expre...@googlegroups.com
Yea I didnt have a full look at it, but I see now you got a new model which means the session and any other class can instantly respond in whatever fashion it wishes....when will 1.0 be out (approx dont have be exact, a valve date if you like :P)?

vision media [ Tj Holowaychuk ]

unread,
Jul 13, 2010, 10:54:53 AM7/13/10
to expre...@googlegroups.com
ya the way middleware is handled in 1.0 via Connect is more robust, still not perfect but dont in a way that each layer can properly respond if it wishes. I am aiming for this week for the release candidate :)
Reply all
Reply to author
Forward
0 new messages