![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
node.js
文章平均质量分 57
xinghua24
这个作者很懒,什么都没留下…
展开
-
Node(19) Global Objects
ReferenceA very important global object is process. process represent the current running node program.console is also a global object. console.log is the most common method to print debug c原创 2012-08-04 05:51:39 · 1467 阅读 · 0 评论 -
Node(23) Express
Express is the most popular Node framework. Use Express to handle get and post are extremely simple.Hello Worldvar app = require('express').createServer();app.get( '/',function( req, res原创 2012-08-05 22:15:29 · 518 阅读 · 0 评论 -
Node(24) Express Project
make a express project using command promptexpress projectNamecd to the projectnpm installgo to localhost:3000 to see the project原创 2012-08-10 07:29:48 · 330 阅读 · 0 评论 -
Node(25) sharing code between client and server
http://caolanmcmahon.com/posts/writing_for_node_and_the_browser/(function(exports){// your code goes hereexports.test = function(){return 'hello world'};})(typeof exports === 'undefined'原创 2012-08-11 04:07:30 · 1357 阅读 · 0 评论 -
Node(7) Routing and serving static pages
Routing usually involve in module url or querystringA simple routing example:var http = require('http');//pages to be routevar pages = [ {route: '/', output: 'Woohoo!'}, {route: '/about/thi原创 2012-07-30 03:32:22 · 552 阅读 · 0 评论 -
Node(3) TCP-based chat server
The TCP server is similar to Http servervar net = require( 'net' );//create a TCP servervar chatServer = net.createServer();chatServer.on( 'connection', function(client){ //send message to cl原创 2012-07-26 22:06:18 · 429 阅读 · 0 评论 -
Node(2) First Code
you can use a command line prompt to do nodemeta-commands.help shows help menu.clear wipes out variablesHello World//include http library into the program//http object has the http原创 2012-07-25 09:57:31 · 285 阅读 · 0 评论 -
Node(8) Events
How to create an event for the class:You have to inherite fro events.EventEmitter to be able to emit and handle eventEventEmitter have on and emit method for handling eventson and addListener ar原创 2012-07-30 04:30:52 · 427 阅读 · 0 评论 -
Node(12) crypto for encrytion
crypto module contains objects and methods for doing encryptionmd5:var crypto = require('crypto');var md5 = crypto.createHash('md5');md5.update('foo');md5.digest( 'HEX' ); //'acbd18db4cc2f8原创 2012-07-30 12:50:30 · 277 阅读 · 0 评论 -
Node(14) assert
assert.equal use == for testing, notEqual use !=, assert.stricEqual use ===, assert.notStricEqual use !==, [message] is the message to be display when assertion failsassert.equal(actual, expected, [原创 2012-07-30 22:16:37 · 565 阅读 · 0 评论 -
Node(16) working with couchDB
Apache CouchDB™ is a database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API. It is a NoSQL database. It is not a relational database.Node example to原创 2012-07-31 10:06:25 · 583 阅读 · 0 评论 -
Node(18) child_process
child_process has stdin and stdout for input and outputchild_process.exec(command, [options], callback)execute a commanddefault options:var options = { encoding: 'utf8',原创 2012-08-01 11:17:43 · 1588 阅读 · 0 评论 -
Node(23) JSON
JSON example profiles.jsmodule.exports = { Peter : { name: 'Peter Parker', age: '18', gender: 'M', grade: 'B' }, Alex : { name: 'Alex Giggersn', age: '23', gender: 'F', grade原创 2012-08-05 19:59:40 · 1207 阅读 · 0 评论 -
Node(10) File System, IO, Stream
Like Http, IO is non-blocking, It is also very commonly used, not as often as Http, but still good to know its funtionality.readFile/readFileSyncfs.readFile(filename, [encoding], [callback])The原创 2012-07-30 11:26:46 · 582 阅读 · 0 评论 -
Node(20) File Upload with formidable module
handling file upload needs to include formidable module, writing raw code for file upload is tough.var http = require('http');var formidable = require('formidable');var form = require('fs').r原创 2012-08-04 23:36:03 · 695 阅读 · 0 评论 -
Node(13) Process
process can be accessed from anywhere in the node. It contains the information about the currently running node thread. it is also a inherited class of EventEmitterproperties:version, platform, up原创 2012-07-30 20:30:33 · 386 阅读 · 0 评论 -
Node(17) Debug
Debug with consoleconsole.log( objects );to see the details of a object use util.inspectutil.inspect(object, [showHidden], [depth], [colors])Debug with EclipseFirst, instal原创 2012-08-01 10:46:46 · 780 阅读 · 0 评论 -
Node(21) DNS- lookup and resolve
resolve IP address:example from node.js APIvar dns = require('dns');dns.resolve4('www.google.com', function (err, addresses) { if (err) throw err; console.log('addresses: ' + JSON.stringi原创 2012-08-05 05:51:52 · 1014 阅读 · 0 评论 -
Node(22) Downloading
example with throttlevar http = require( 'http');var fs = require( 'fs');var options = {};options.file = 'pride.txt';options.fileSize = fs.statSync( options.file).size;options.kbps = 32;htt原创 2012-08-05 08:28:49 · 772 阅读 · 0 评论 -
Node(4) Module
Every javascript file in itself is a moduleThe require function searches for modules, and loads the module definition into the Node runtimea module that defines a next function//simple.原创 2012-07-27 07:28:48 · 378 阅读 · 0 评论 -
Node(11) Event Driven and Non-blocking
In node you can not put the processor to sleep any how even setTimeout is not actually putting the processor to wait!Everything is driven by event and callback!Request are non-blocking, you ha原创 2012-07-30 11:51:47 · 299 阅读 · 0 评论 -
Node(9) HTTP
http is the core object in Node.main objects:http - can create a Server object, common methods: createServer(), get() and request().http.Server - server can be created by http. common methods: l原创 2012-07-30 06:37:19 · 432 阅读 · 0 评论 -
Node(1) Intro and refernce
node.js APIAPI with exampletutorialnodebeginner guidenode is a wrapper on high-performance V8 JavaScript runtime. node is often referred to as server side javascript. But a better way to原创 2012-07-25 06:53:12 · 314 阅读 · 0 评论 -
Node(5) URL and Query String
Node.js Referenceget the pathname from url string:var pathname = url.parse(req.url).pathname;URLurl.parse(urlStr, [parseQueryString], [slashesDenoteHost])return a URL objectvar htt原创 2012-07-28 09:09:40 · 1041 阅读 · 0 评论 -
Node(6) Accessing GET and POST data using http.ServerRequest
http.ServerRequest or simply request contains information from GET or POSTGet objects are in urlquerystring.parse() turn the post data into an objectGETGET example:var http = req原创 2012-07-29 00:08:16 · 553 阅读 · 0 评论 -
Node(15) vm
vm is similar to eval(), but eval() can change the surrounding context, whereas vm cannotvm is like creating a sandbox, the code will be executed in the different namespace instead of running in the原创 2012-07-31 00:21:29 · 611 阅读 · 0 评论