Great, someone who doesn't want to use express! I myself find this 
framework too specific as well. However, there are true advantages in using 
existing projects instead of re-inventing the wheel. Since the node http 
server is a bit rough around the edges though, some sort of http framework 
is recommended. Here's my pick:

 - Use connect (on which express is based) for the basic functionality ( 
http://www.senchalabs.org/connect/ ) as the webserver framework.

 - Use bodyparser middleware for POST request bodies.

 - Write your own middleware for API access.

 - Use static middleware for static file serving from a directory

 - You can copy&paste this gist: https://gist.github.com/klovadis/4988305

Connect basically allows you to execute so called middleware functions on a 
http request in a linear order. Whenever a request comes in, each function 
does something (i.e. modify the request object to add cookie information) 
if applicable and continues to the next middleware, or responds to the 
request and skips the remaining middleware functions. So the order in which 
the middleware functions are added matters - you want to have decorating 
functions at the beginning and a "catch all" function at the end. The 
documentation of the exact workings of connect - to state things nicely - 
has room for improvement though.

Express is based on connect and the way it works with middleware functions, 
but adds a lot of functionality for which you otherwise need to write your 
own middleware (i.e. a router or rendering jade templates out of the box). 
That is why lots of people do use express (*and tend to recommend it as the 
one and only solution whenever the word "webserver" is present*).

In fact many other webserver frameworks do exist and are worth having a 
look at, but since I do know connect quite well by now I therefore 
recommend using it (without express on top of it).

So in a nutshell: Place all your static files in a subfolder and let the 
"static" middleware serve them. Add api logic in a middleware function. No 
additional functionality is present. But do read up on the coolness of jade 
and stylus some time, there is a reason why people use those.

All the best,

Geerten


On Tuesday, February 19, 2013 3:35:53 PM UTC+1, kanitkar...@gmail.com wrote:
>
> Hi,
>
> I would like to do the following,
>
> 1) Have regular .html .css & .js files just like a normal web app
>
> 2) Interact with Node Js only through Ajax calls
>
> 3) But All files mentioned in 1) are also hosted on the same Node Http 
> server.
>
> So when I say http://localhost:3000/index.html, Node Js server should 
> give me index.html along with all css & js files included in it.
>
> Then my Javascript & Ajax code should drive the functionality with Node 
> program getting called by ajax request.
>
> Can anyone please please suggest me the best way to do this ?
>
> I don't want to use Jade or Stylus. I want to develop as if I am using 
> tomcat or wamp server & use power of Node where ever needed only.
>
> I am aware of express js framework but don't know how it will be useful 
> for above scenario.
>

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
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 nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to