日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

node js 开发网站_使用Node JS开发网站

發(fā)布時間:2025/3/11 javascript 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 node js 开发网站_使用Node JS开发网站 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

node js 開發(fā)網(wǎng)站

You will have your own fully functional website running on "localhost" after going through this article.

閱讀完本文后,您將在“ localhost”上運行自己的功能齊全的網(wǎng)站 。

Basic knowledge of JavaScript and HTML is a prerequisite.

必須具備JavaScript和HTML的基礎(chǔ)知識。

Here are the source codes of the webpages...

這是網(wǎng)頁的源代碼...

JS file (a.js)

JS檔案(a.js)

var http = require('http');var fs = require('fs');function notfoundfunc(response) {response.writeHead(404, {"Context-Type": "text/plain"});response.write("page not found");response.end(); }function myfunc(request, response) {if (request.method == 'GET' && request.url == '/') {response.writeHead(200, {"Context-Type": "text/html"});fs.createReadStream("./index.html").pipe(response);} else if (request.method == 'GET' && request.url == '/about') {response.writeHead(200, {"Context-Type": "text/html"});fs.createReadStream("./about.html").pipe(response);} else {notfoundfunc(response);} }http.createServer(myfunc).listen(3500); console.log("server made");

index.html

index.html

<html><body>welcome to my website.</body></html>

about.html

about.html

<html><body>developed by mansha lamba.</body></html>

Output screenshot 1

輸出屏幕截圖1

Output screenshot 2

輸出屏幕截圖2

Output screenshot 3

輸出屏幕截圖3

Explanation of the code:

代碼說明:

The source code is very easy to understand.

源代碼非常容易理解。

Please note that instead of giving a plain text output like in my previous article here I have used HTML files. For that, another inbuilt module in NODE JS is used i.e. fs.

請注意,不是使用純文本輸出,而是使用HTML文件。 為此,使用了NODE JS中的另一個內(nèi)置模塊,即fs。

Rest of the code is self-explanatory.

其余代碼是不言自明的。

翻譯自: https://www.includehelp.com/node-js/developing-a-website.aspx

node js 開發(fā)網(wǎng)站

總結(jié)

以上是生活随笔為你收集整理的node js 开发网站_使用Node JS开发网站的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。