Using node.js as a simple web server

后端 未结 30 2762
感情败类
感情败类 2020-11-22 02:54

I want to run a very simple HTTP server. Every GET request to example.com should get index.html served to it but as a regular HTML page (i.e., same

30条回答
  •  情书的邮戳
    2020-11-22 03:11

    Edit:

    Node.js sample app Node Chat has the functionality you want.
    In it's README.textfile
    3. Step is what you are looking for.

    step1

    • create a server that responds with hello world on port 8002

    step2

    • create an index.html and serve it

    step3

    • introduce util.js
    • change the logic so that any static file is served
    • show 404 in case no file is found

    step4

    • add jquery-1.4.2.js
    • add client.js
    • change index.html to prompt user for nickname

    Here is the server.js

    Here is the util.js

提交回复
热议问题