nodejs
共 9 篇文章
coffeescript+prototypejs使编写nodejs更象ruby-like
首先安装prototype for nodejs npm install prototype 看个例子 prototype = require 'prototype' Object.extend global, prototype (9).times (x)-> console.log x [1,2,3,4].each (x)-> console.log x Person = Class.create #定义一个类 initialize: (name)-> @name = name say: (message)-> "#{@name}:#{message}" Pirate = Class.c…
2011-12-21 12:01 · nodejs · coffeescript
Underscore.js与nodejs相结合
今天发现这个Underscore.js,文档说 http://documentcloud.github.com/underscore/ Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby)。 提供了许多类似ruby风格的函数,这是我所喜欢的。 看几个例子。 安装 npm install underscore 在nodes.js中测试 …
2011-12-14 11:18 · nodejs
NowJS and Reconnects
NowJS and Reconnects 保留 原文http://blog.nowjs.com/ This particular feature has been highly anticipated by the NowJS community for some time. With the switch to Socket.IO 0.6.18, which now has built-in support for socket reconnecting, implementation of this feature was actually quite doable. We've tes…
2011-12-14 09:03 · nodejs
Nodejs中的EventEmitter
EventEmitter是nodejs核心的一部分。很多nodejs对象继承自EventEmitter,用来处理事件,及回调。来看API中的例子 var util = require("util"); var events = require("events");//EventEmitter通过events模块来访问 function MyStream() {//新建一个类 events.EventEmitter.call(this); } util.inherits(MyStream, events.EventEmitter);//使这个类继承EventEmitter MyStream.p…
2011-12-14 04:57 · nodejs
nodejs+nowjs实现聊天室
支持多房间,支持私聊,使用nowjs库,服务器端代码不到100行。需要jquery1.7.1和coffee-script.js,读者可自行下载。 重点: 1、nowjs中Group的使用,如何遍历Group内的users。 2、客户端如何异步调用服务器端函数。 3、如何与特定用户通信。 运行 node app.js 在浏览器中访问 http://localhost:8080 app.js require('coffee-script'); require('./chatroomserver'); chatroomserver.coffee coffeescript代码,重点部分已加上注释 f…
nowjs和nodejs结合的简单示例
功能:把服务器端的时间new Date().getTime()传送到客户端,主要测试实时性。轮询间隔为10ms时,能正常显示。可同时打开多个窗口,设置不同轮询时间,各个窗口可独立运行。 服务器端代码: 用coffeescript编写 server.coffee fs = require 'fs' url = require 'url' html = fs.readFileSync(__dirname + '/simple.html') #注意,这里要指向你自己的jquery库地址 jquery = fs.readFileSync(__dirname + '/../node/jquery-1.…
nodejs运行coffeescript
首先安装coffee-script npm install coffee-script 在js文件中加入下面代码 require('coffee-script');//引用coffeescript模块 require('./mytest');//指向要运行的coffeescript文件,可加多个文件。 就可以node xx.js,来运行coffeescript文件了。
2011-12-10 03:05 · nodejs
nowjs和nodejs实现服务器端与客户端实时数据传输的例子
参考: http://www.bennadel.com/blog/2171-Realtime-Messaging-And-Synchronization-With-NowJS-And-Node-js.htm 先说例子实现的功能。网页上有一图片,图片可以拖动。用浏览器打开多个同一网页,当图片移动时,其它页面的图片会同步移动。例子也展示了用jQuery实现图片的拖动。 测试环境window7,nodejs v0.6.5 分别用ie,firefox,chrome打开 http://127.0.0.1:8080/client.html ,所有该网页上的图片会同步移动。贴上代码。 server.js端…
2011-12-09 03:38 · nodejs
用socket.io实现WebSocket的一个简单例子
用socket.io实现WebSocket的一个简单例子 客户端代码: <html> <head> <title></title> <script src="../js/socket.io.client.js"></script> <script type="text/javascript"> function doit() { var socket = io.connect('http://localhost'); socket.on('news', function (data) {//接收到服务器发送过来的名为'new'的数据 console.log(data.hello);//dat…
2011-12-07 10:47 · nodejs