Node js web server- Issues and Questions.

I am new to node js. These are my questions

  1. Can I able to deliver html pages, which have javascripts , css etc. May be inline or refering from an external page ?
  2. Is it possible to display pages based on the request ? Eg: http://localhost:1234/ -> index.html or http://localhost:1234/Users.html -> users.html
  3. Is there any folder structure to be maintained to achieve the above requirement
  4. I have html pages and planning to use ajax request to server. Is it possible ?

These are my doubts. I made a small server which can able to display static html. But I need to hard code the physical file. That is working, but when I changed my html which contains reference to jquery files. it display file not found in console.

I am working in a windows 7 machine.

1 Yes, node.js can serve html pages with images, css or javascript

2 Yes, you can set different pages for different URL's

3 Your choice, but you should to stick to folder structure, its better to be organised right. Here's a typical structure.

├───node_modules // installed npm packages 
│   ├───.bin
│   ├───express
│   ├───jade
├───public
│   ├───data         //created for other files
│   ├───img          //all my image files
│   ├───javascripts  //all my js files
│   └───stylesheets  //all my css files
├───routes  //handling routes for urls
├───Temp    //created by me for temp stuff
└───views   //all the static files you want to put

4 Yes, node.js can accept/respond to AJAX requests

file not found is the error you get when you specify incorrect file location. If you use relative paths in your code like ./view rather than /view, it is relative to where you start the node.js server.

A lot of what you're asking about comes down to "How do I serve static content using Node?" And for that I recommend Express, which is documented here: http://expressjs.com/api.html - specifically the "static" serving features, which will let you serve whole files from a directory, easily, within Node, even if your program also serves dynamic content.