nodejs入门教程二:创建一个简单应用示例
网络编程 2021-07-04 18:32www.168986.cn编程入门
这篇文章主要介绍了nodejs入门教程之创建一个简单应用的方法,涉及nodejs http模块的引用、端口监听等相关操作技巧,需要的朋友可以参考下
本文实例讲述了nodejs创建一个简单应用的方法。分享给大家供大家参考,具体如下:
1.创建 test.js
// require 来载入 http 模块 var http = require('http'); /** * 使用 http.createServer() 方法创建服务器,返回 一个对象 * 对象有一个叫做 listen 的方法,并使用 listen 方法绑定 8000 端口。 * 函数通过 request, response 参数来接收和响应数据。 */ http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); if(request.url!=="/favicon.ico"){ //清除第2此访问 console.log('访问'); response.write('hello,world'); response.end('hell,世界');//不写 end() 则没有http协议尾,但写了会产生两次访问 } }).listen(8000); console.log('Server running at http://127.0.0.1:8000/');
2. 执行
node test.js
结果:Server running at http://127.0.0.1:8000/
3. 在浏览器访问 http://127.0.0.1:8000
希望本文所述对大家nodejs程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程