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

node js 开发网站

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

阅读完本文后,您将在“ localhost”上运行自己的功能齐全的网站

Basic knowledge of JavaScript and HTML is a prerequisite.

必须具备JavaScriptHTML的基础知识。

Here are the source codes of the webpages...

这是网页的源代码...

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

Develop a website in Node Js | Output file 1

Output screenshot 2

输出屏幕截图2

Develop a website in Node Js | Output file 2

Output screenshot 3

输出屏幕截图3

Develop a website in Node Js | Output file 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中的另一个内置模块,即fs。

Rest of the code is self-explanatory.

其余代码是不言自明的。

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

node js 开发网站

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543959.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

hdu 1166 敌兵布阵

Problem DescriptionC国的死对头A国这段时间正在进行军事演习&#xff0c;所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段&#xff0c;所以每个工兵营地…

Java:LocalDate / LocalDateTime加减时间

在线API参考&#xff1a;LocalTime (Java Platform SE 8 ) 方法介绍 方法1方法1说明plusYears(long years) minusYears(long years) 返回增加/减少了年数的副本plusMonths(long months) minusMonths(long months)返回增加/减少了月数的副本plusWeeks(long weeks) minusWeeks(…

集合 List 分片的 5 种实现

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;前些天在实现 MyBatis 批量插入时遇到了一个问题&#xff0c;当批量插入的数据量比较大时&#xff0c;会导致程序执行报错&a…

消失的死锁

问题描述 如果java层面发生了死锁&#xff0c;当我们使用jstack命令的时候其实是可以将死锁的信息给dump出来的&#xff0c;在dump结果的最后会有类似Found one Java-level deadlock:的关键字&#xff0c;接着会把发生死锁的线程的堆栈及对应的同步锁给打印出来&#xff0c;这次…

ruby 新建对象_Ruby中的面向对象编程

ruby 新建对象Before getting into understanding how Object-oriented programming is implemented in Ruby, let us first understand what Object Oriented means. 在了解如何在Ruby中实现面向对象的编程之前&#xff0c;让我们首先了解面向对象的含义。 Object-oriented p…

使用它给 ​xxl-job 添加任务,太爽了

xxl-job是一款非常优秀的任务调度中间件&#xff0c;轻量级、使用简单、支持分布式等优点&#xff0c;让它广泛应用在我们的项目中&#xff0c;解决了不少定时任务的调度问题。我们都知道&#xff0c;在使用过程中需要先到xxl-job的任务调度中心页面上&#xff0c;配置执行器ex…

dubboSPI机制浅谈

2019独角兽企业重金招聘Python工程师标准>>> &#xfeff;&#xfeff;&#xfeff;本文重点讲述SPI机制&#xff0c;从jdk和dubbo 1、jdk spi机制 2、dubbo spi实现 首先spi是什么&#xff1f; SPI是为某个接口寻找服务实现的机制。为了实现在模块装配的时候能不在…

python 类中静态变量_Python中的类或静态变量

python 类中静态变量Python类/静态变量 (Python Class / Static Variables) Class or Static variables are class-related variables that are shared among all objects but the instance or non-static variable is unique for each object. In Python, there is no need fo…

彻底搞懂 SpringBoot 中的 starter 机制

前言我们都知道&#xff0c;Spring的功能非常强大&#xff0c;但也有些弊端。比如&#xff1a;我们需要手动去配置大量的参数&#xff0c;没有默认值&#xff0c;需要我们管理大量的jar包和它们的依赖。为了提升Spring项目的开发效率&#xff0c;简化一些配置&#xff0c;Sprin…

android四大组件之Service 注册广播接收者

广播的注册一共有两种&#xff0c;一种就是用清单文件注册&#xff0c;还有另外一种就是用代码注册&#xff0c;代码注册比较灵活&#xff0c;可以在需要的时候注册&#xff0c;不需要的时候解除注册 用服务注册广播首先要开启服务&#xff0c; 然后在服务oncreate方法里注册广…

c ++向量库_将向量复制到C ++中的另一个向量

c 向量库The ways that we are using to copy vectors in C, are: 我们用于在C 中复制向量的方法是&#xff1a; Copy one vectors elements to another (Simple approach) 将一个向量的元素复制到另一个(简单方法) Copy vector by using an assignment operator 通过使用赋值…

Java 中验证时间格式的 4 种方法

大家好&#xff0c;今天咱们来讲一下&#xff0c;Java 中如何检查一个字符串是否是合法的日期格式&#xff1f;为什么要检查时间格式&#xff1f;后端接口在接收数据的时候&#xff0c;都需要进行检查。检查全部通过后&#xff0c;才能够执行业务逻辑。对于时间格式&#xff0c…

FreeSWITCH的TLS加密

听着很高大上&#xff08;实际也很实用&#xff09;的加密机制&#xff0c;在FreeSWITCH里配置支持竟然这么简单&#xff01; Greate FreeSWITCH and Greate Programmer&#xff01; ① cd /usr/local/freeswitch/bin&#xff08;以默认的安装路径为例&#xff09; ② 产生root…

kotlin 查找id_Kotlin程序查找Sphere的体积

kotlin 查找idFormula to find volume of Sphere: volume (4/3)*PI*r^3 查找球体体积的公式&#xff1a; volume (4/3)* PI * r ^ 3 Given the value of radius, we have to find the volume of Sphere. 给定半径的值&#xff0c;我们必须找到球体的体积。 Example: 例&#…

Redis 实现分布式锁的 7 种方案

前言日常开发中&#xff0c;秒杀下单、抢红包等等业务场景&#xff0c;都需要用到分布式锁。而Redis非常适合作为分布式锁使用。本文将分七个方案展开&#xff0c;跟大家探讨Redis分布式锁的正确使用方式。如果有不正确的地方&#xff0c;欢迎大家指出哈&#xff0c;一起学习一…

css复选框样式_使用CSS样式复选框

css复选框样式Introduction: 介绍&#xff1a; Sometimes we want to develop a website or web page that would contain a form and through that form, we want to get some information from the user. Now that information could be of any type depending on the kind …

大数据计算平台Spark内核全面解读

1、Spark介绍 Spark是起源于美国加州大学伯克利分校AMPLab的大数据计算平台&#xff0c;在2010年开源&#xff0c;目前是Apache软件基金会的顶级项目。随着Spark在大数据计算领域的暂露头角&#xff0c;越来越多的企业开始关注和使用。2014年11月&#xff0c;Spark在Daytona Gr…

javascript对话框_JavaScript中的对话框

javascript对话框JavaScript对话框 (JavaScript Dialog Boxes) Dialog boxes are a great way to provide feedback to the user when they submit a form. In JavaScript, there are three kinds of Dialog boxes, 对话框是向用户提交表单时提供反馈的好方法。 在JavaScript中…

排查死锁的 4 种工具,秀~

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;死锁&#xff08;Dead Lock&#xff09;指的是两个或两个以上的运算单元&#xff08;进程、线程或协程&#xff09;&#xf…

MySQL 常见的 9 种优化方法

大家好&#xff0c;我是磊哥&#xff01;今天给大家分享一些简单好用的数据库优化方式&#xff01;1、选择最合适的字段属性Mysql是一种关系型数据库&#xff0c;可以很好地支持大数据量的存储&#xff0c;但是一般来说&#xff0c;数据库中的表越小&#xff0c;在它上面执行的…