We can create Template Helpers, which can contains some common reuseable data and libs. /* This is a file of data and helper functions that we can expose and use in our templating function */ // FS is a built in module to node that let's us read file…
之前编写后台接口,测试数据都是使用的Postman,相当的方便,之前也一直使用get方法,编写Node.js一直没有问题,但是由于要编写一个注册/登陆的功能,所以发送的post数据,后台的逻辑已经编写完成,但是当使用post传来数据时req.body中却为空,翻看半天以前的项目代码,也没有发现我哪里写错了. 最后确定是Postman需要进行设置 这个图是摘自:http://drupal.stackexchange.com/questions/50559/services-module-how-t…
Simple Redis Commands Let's start practicing using the redis key-value store from our node application. Require the redis module and assign it to a variable called redis. var redis = require('redis'); Create a redis client and assign it to a variable…
 Connect is a middleware layer for Node.js   http://senchalabs.github.com/connect Connect Connect is an extensible HTTP server framework for node using "plugins" known as middleware. var connect = require('connect') var http = require('http') va…
原文摘自我的前端博客,欢迎大家来访问 http://www.hacke2.cn 第二章 Js概览 基于GoogleV8引擎 Object.keys(o) 数组方法:遍历forEach.过滤filter.改变map 实现了String.prototype.trim() 含有JSON解析 第三章 阻塞与非阻塞IO 单线程注意点 小心处理内存中的变量,可能会影响两次访问的结果 不要编写阻塞式代码,可能会影响第二次访问的时间 事件轮训 先注册事件 不断询问这些事件是否已经分发dispatch 当事件分发…
异步读取文件 按照js的标准,异步读取一个文本文件的格式如下: 'use strict' const fs = require('fs') fs.readFile('test.txt', 'utf-8', function(err, data){ if(err){ cconsole.log(err) }else{ console.log(data) } }) 1 2 3 4 5 6 7 8 9 10 11 请注意,test.txt文件必须在当前目录下,且文件编码必须为utf-8 如果我们读取的文…
Node.js代码 var express = require('express'); var app = express(); var http = require('http'); var server = http.createServer(app); app.set('trust proxy', true);// 设置以后,req.ips是ip数组:如果未经过代理,则为[]. 若不设置,则req.ips恒为[] app.get('/', function(req, res){ conso…
Outline 5 构建Web应用程序 5.1 构建和使用HTTP中间件 5.2 用Express.js创建Web应用程序 5.3 使用Socket.IO创建通用的实时Web应用程序 5 构建Web应用程序 5.1 构建和使用HTTP中间件 5.1.1 Web开发的常见任务: (1) HTTP服务器负责的任务 解析请求URL.维护会话关联.持久化会话数据.解析Cookie等. (2) 业务程序可以参与的任务 检查和修改请求和响应,一些Web框架正是包装了请求和响应的传递链以方面业务程序的编码工作…
目录 前言 1 不使用开发工具 1.1 自动重启工具 1.2 浏览器自动刷新工具 2 阻塞event loop 3 频繁调用回调函数 4 圣诞树结构的回调(回调的地狱) 5 创建一个大而完整的应用程序 6 缺少日志 7 没有测试 8 不使用静态分析工具 9 没有监视与性能分析 10 使用console.log来debug 前言 随着一些大公司如Walmart,PayPal等开始采用Node.js,在过去的几年里,Node.js有了快速的增长.越来越多的人开始选择Node并发布modules到NP…
express 标签(空格分隔): node.js express [TOC] 安装: 新版本中命令行工具分家了 npm install -g express //安装 express 然后 npm install -g express-generator //安装 express 命令行工具 express -V 我现在查看到的版本是 4.9.0 npm start 代替 node app.js 启动 http.Server var http = require(‘http’); var se…