下载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. 删除从第i个位置开始,长度为len的子串

    /*字符串采用带头结点的链表存储,设计算法函数void delstring(linkstring s, int i,int len)在字符串s中删除从第i个位置开始,长度为len的子串.*//**** ...

  2. UI基础之UIButton相关

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 1.按钮透明效果 btn.alpha = 0.8; 2.按钮圆角处理 btn ...

  3. dom4j使用xpath报异常 Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext

    Exception in thread "main" java.lang.NoClassDefFoundError: org/jaxen/NamespaceContext      ...

  4. centos安装lamp环境

    通过yum安装,需要联网且为su账号 yum -y install httpd php mysql mysql-server php-mysql 设置开启启动mysql,httpd     /sbin ...

  5. 在 Mac OS 上使用 TypeScript 编写 ASP.NET Core 1.0 应用

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  6. init.css

    [24/7金,15] Mon Feb 29 2016 16:29:25 GMT+0800 yahoo.css.yahari @charset "utf-8"; /*yahoo*/ ...

  7. 【转】浅谈html5网页内嵌视频

    转自 http://www.pchou.info/web/2014/01/30/52ea01e13a7f1.html

  8. 举例详解CSS中的cursor属性

    这篇文章主要举例介绍了CSS中的cursor属性,包括zoom-in/zoom-out和grab/grabbing等常用属性值的使用,需要的朋友可以参考下 一.开篇之言 CSS3的领域范围已经渗透到了 ...

  9. uva-10305

      题意:给出n个任务,任务不是完全独立的,有些任务必须依赖另外一些任务才能执行:m个任务关系. 输出:n个任务的可能执行顺序: 我的解决方法:这就是个赤裸裸的拓扑排序,直接dfs拓扑每一个任务点,然 ...

  10. 各廠商ERP系統架構圖連結 (ERP流程圖)(轉)

    各廠商ERP系統架構圖連結 (ERP流程圖)   資料來源 Google圖片搜尋ERP整理而來 資通電腦 ArgoERP 資通電腦 Oracle ERP 鼎新電腦 Workflow ERP鼎新電腦 S ...