下载node安装npm什么的就不说了

入门总结

http://www.cnblogs.com/Darren_code/archive/2011/10/31/nodejs.html

进入node_HOME目录

test.js

/*var hello = require('./hello.js');
console.log('hello.location : ' + hello.location)
console.log('hello.location : ' + hello.name)
hello.showLog();*/ var fs = require('fs');
  console.log('');
var hello = require('./hello.js');
  console.log('');   fs.readFile('./hello.js', function (err, data) {
    if (err) throw err;
    console.log('successfully');
  });
  console.log('async'); var events = require("events");
  var emitter = new events.EventEmitter();
  emitter.on("myEvent", function(msg) {
    console.log(msg);
  });
  emitter.emit("myEvent", "Hello World."); var fs = require('fs');
  fs.unlink('./hello.js', function (err) {
    if (err) throw err;
    console.log('successfully deleted myModule.js');
  });

hello.js

  console.log('');
var name = "Darren";
  this.location = "Beijing";
  this.showLog = function(){
   console.log('Hi Darren.')
  };

输出:

11
00
22
async
Hello World.
successfully deleted myModule.js
successfully

基本概念的解析:

模块:其实就相当于一个js类, 通过require(路径)方式创建并引入一个模块

异步:

node各内置模块及其api

sys

fs

http

agent

url

path

file

events

http://nodejs.iteye.com/blog/1587019

通常, js 通过eval 组装 服务端传来的 json字符串成 js对象 -- 服务端有另外的json解释器

var aa = JSON.parse("{\"a\":\"c\"}");   JSON 也是js内置的

服务端对浏览器的请求处理通常是: 每个请求建立一个线程。。。?

一定要明白你需要解决的问题是什么,基于此采取最佳解决方案,而不是基于你当下所掌握的技能来解决遇到的问题

node的优势:

无阻塞(异步)、

高并发(异步、基于事件的i/o)

构建可伸缩的网络应用(单线程_ 传统web服务器的一个请求一个线程,即多线程)

非常棒的文章:

http://www.cnblogs.com/liusuqi/p/3735491.html

node.js小结 2的更多相关文章

  1. Node.js之Console用法小结

    /** * Created by city--online on 16/3/9. */ //console.time()和console.timeEnd()输出中间代码的执行时间(注意:time和ti ...

  2. 学习Node.js知识小结

    什么是Node.js 官方解释:Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js使用了一个事件驱动.非阻塞式I/O的模型( Node.js的特性 ...

  3. Node.js 教程 02 - 经典的Hello World

    前言: Node.js的介绍.安装及配置,上一节都已经介绍过了,如果有不清楚的也可以留言或者直接问度娘. 本节: 本节主要以一个简单的例子简单体验一下Node.js,用到了两种方法.下面会介绍. 总之 ...

  4. Node.js 教程 03 - 创建HTTP服务器

    前言: 如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi. 从这个角度看,整个"接收 HTTP 请 ...

  5. Node.js 教程 06 - 函数

    前言: 本篇介绍的是Node.js中的函数,相对于上一篇会简单一点,其实和我们Javascript中的function无异. 好了,废话不多说了,我们进入正题吧. Node.js函数: [示例1:创建 ...

  6. 10个常见的Node.js面试题

    如果你希望找一份有关Node.js的工作,但又不知道从哪里入手评测自己对Node.js的掌握程度. 本文就为你罗列了10个常见的Node.js面试题,分别考察了Node.js编程相关的几个主要方面. ...

  7. node.js的安装环境搭建

    .header { cursor: pointer } p { margin: 3px 6px } th { background: lightblue; width: 20% } table { t ...

  8. 《深入浅出Node.js》第6章 理解 Buffer

    @by Ruth92(转载请注明出处) 第6章 理解 Buffer ✁ 为什么需要 Buffer? 在 Node 中,应用需要处理网络协议.操作数据库.处理图片.接收上传文件等,在网络流和文件的操作中 ...

  9. 深入浅出Node.js(一):什么是Node.js

    Node.js从2009年诞生至今,已经发展了两年有余,其成长的速度有目共睹.从在github的访问量超过Rails,到去年底Node.jsS创始人Ryan Dalh加盟Joyent获得企业资助,再到 ...

随机推荐

  1. Layout in Rails

    参考链接:http://guides.rubyonrails.org/layouts_and_rendering.html#structuring-layouts layout layout最基本的使 ...

  2. GCC4.8.2升级安装

    一.查看本机GCC版本: 使用gcc -v 查看本机版本信息,我的gcc版本为: gcc 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) 二.升级或安装编译器: 1 ...

  3. PhpStorm破解教程

    http://www.cnblogs.com/buyucoder/p/5291771.html

  4. windows下监测tomcat7内存使用情况

    在conf里面的server-user文件里添加 <tomcat-users> <role rolename="admin-gui"/> <user ...

  5. nginx启动脚本

    #!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig:   - 85 15 # descr ...

  6. Win8.1下FreeImage.lib库的配置和简单使用(转)

    转自http://www.codeweblog.com/win8-1下freeimage-lib库的配置和简单使用/ 首先,你可以从这里获取FreeImage的完整库文件(访问密码 9a5e). 配置 ...

  7. C# Exception 写入文件

    /// <summary> /// 将异常打印到LOG文件 /// </summary> /// <param name="ex">异常< ...

  8. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

  9. iOS开发之AppIcon及LaunchScreen设置

    一.AppIcon设置 具体设置步骤如下图: 二.LaunchScreen设置与停留时间设置 具体设置步骤如下图: 通过程序可以增加背景的停留时间:

  10. GDB调试精粹及使用实例(转)

    一:列文件清单 1. List (gdb) list line1,line2 二:执行程序 要想运行准备调试的程序,可使用run命令,在它后面可以跟随发给该程序的任何参数,包括标准输入和标准输出说明符 ...