nodejs入门(02)-hello world

xiaoxiao2021-02-28  141

1,编写代码

2,运行服务器

3,源码地址


1,编写代码

创建一个js文件,名字为01hello.js,编写代码

/** * Created by boy on 2017/7/10. */ //1,引用http var http = require("http"); //2,创建Server对象,并且监听。 http.createServer(function (request, response) { // 发送 HTTP 头部 // HTTP 状态值: 200 : OK // 内容类型: text/plain response.writeHead(200, {'Content-Type': 'text/plain'}); // 发送响应数据 "Hello World" response.end('Hello World\n'); }).listen(8888); // 3,终端打印如下信息 console.log('Server running at http://localhost:8888/');

2,运行服务器

(1)进入项目目录 (2)运行nodejs。 (3)在浏览器输入http://localhost:8888/,如果出现hello world信息就成功。


3,源码地址

http://download.csdn.net/download/wzjisking/9893727

转载请注明原文地址: https://www.6miu.com/read-18493.html

最新回复(0)