0

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.

4

2 に答える 2

1

あなたが尋ねていることの多くは、「Node.js を使用して静的コンテンツを提供するにはどうすればよいですか?」ということになります。そのためには、ここに文書化されている Express をお勧めします: http://expressjs.com/api.html - 具体的には、ディレクトリからファイル全体をノード内で簡単に提供できる「静的」サービス機能です。プログラムは動的コンテンツも提供します。

于 2013-02-17T09:18:48.470 に答える
1

1 はい、node.js は画像、css、または javascript を含む html ページを提供できます

2 はい、URL ごとに異なるページを設定できます

3 選択は自由ですが、フォルダ構造に固執する必要があります。適切に整理することをお勧めします。ここに典型的な構造があります。

├───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 はい、node.js は AJAX リクエストを受け入れ/応答できます

file not found は、間違ったファイルの場所を指定したときに表示されるエラーです。のようにコード内で相対パスを使用する場合./view/viewそれは node.js サーバーを起動した場所からの相対パスです。

于 2013-02-17T09:21:13.270 に答える