2. nodejs 基础学习
来源:互联网 发布:淘宝卖家推广平台 编辑:程序博客网 时间:2024/05/16 17:07
注意: 本文档的书写源自何老师 在51cto上的讲解。
部分代码来源:http://www.yuankuwang.com
何老师视频:http://edu.51cto.com/course/course_id-7066.html (for free)
前提是,我们已经保证了nodejs的环境已经完成
1 在屏幕上打印hello world
(1) touch hello.js
(2) echo “console.log('hello world‘)” > hello.js
(3) node hello.js
when you finish step 3, you will find the hello world in the terminal.
2. 如何实现简单的网页访问(http)
(1)touch http.js
(2).w var http = require('http');
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,世界');//不写则没有http协议尾, 在浏览器端会出现转圈,但写了会产生两次访问
}
}).listen(8000)
console.log('Server running at http://127.0.0.1:8000/');
3. 函数
普通函数:在调用的同一个文件下,可以直接调用
//---普通函数
function fun1(res){
res.write("你好,我是fun1");
}
非普通函数:不在同一个文件下
(1)mkdir models ; touch function.js
(2) //在一个文件中,只包含一个函数
function controller(req,res){
call('hello',req,res);
res.end("");
}
function call(res){
console.log('call');
}
module.exports = controller;
//包含多个函数
var otherfun = require('./models/function.js');
module.exports={
getVisit:function(){
return visitnum++;
},
add:function(a,b){
return a+b;
}
}
- 2. nodejs 基础学习
- nodeJS基础学习
- nodejs基础学习笔记
- NodeJS学习(一) NodeJS基础
- nodejs基础学习--模块安装
- windows下《七天学会NodeJS》学习笔记之一--NodeJS基础
- 学习nodejs部分基础内容入门小结
- Nodejs 基础
- NodeJS基础
- nodeJs基础
- NodeJS基础
- NodeJS基础
- nodejs基础
- NodeJS基础
- nodejs 基础
- nodejs基础
- NodeJs基础配置、核心概念与学习路线回顾
- nodejs学习
- 1024. 科学计数法 (20)
- 欢迎使用CSDN-markdown编辑器
- outlook2013配置
- C++里,我们通过在一个类中重载括号运算符的方法使用仿函数
- C#调用C++的dll
- 2. nodejs 基础学习
- java方法重载与递归调用
- eclipse java文件右上角标识(区别class文件和interface文件)
- 初窥linux环境变量
- Git常用命令
- 斐波那契数列-数组与递归方式-C描述
- 设置Glide加载图片时的loading效果
- AndroidStudio工程导入jar包和so第三方库
- Mac系统利用VirtualBox虚拟机安装windows7系统