日志输出方式

node test.js 2>error.log 1>info.log

如果需要日志文件追加 node test.js 2>>error.log 1>>info.log

如果是用 sublimeText-Nodejs 需要在 Nodejs.sublime-build 中修改以下节点(根据自己的操作系统)

"cmd": ["taskkill /F /IM node.exe & node $file 2>>error.log 1>>info.log", ""]

如果不设置,默认输出到系统console

日志语法

console.log('Server running at http://127.0.0.1:8888/');
console.info('text: %s !', message);
console.error('this is a error');
console.warn('this is a warn');

node.js中日志中无法区分warn或者error,统一保存在异常日志中

输出某段代码执行时间

console.time("hi");
console.log("it works!");
console.timeEnd("hi");  

http

一个简单的http服务

var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('Hello World\n');
}).listen(8888);
console.log('Server running at http://127.0.0.1:8888/');

一个简单的http客户端

http.get({
hostname: 'localhost',
port: 8888,
path: '/',
agent: false // create a new agent just for this one request
}, function (res) {
var data = '';
res.on('data', function (chunk){
data += chunk.toString();
});
res.on('end',function (){
console.log("data is:"+data);
});
});
http.get('http://localhost:8888',function (res) {
var data = '';
res.on('data', function (chunk){
data += chunk.toString();
});
res.on('end',function (){
console.log("data is:"+data);
});
});

  

  

最新文章

  1. [LeetCode] K-th Smallest in Lexicographical Order 字典顺序的第K小数字
  2. http 协议集合,超级简单
  3. [原创]PCB知识补充
  4. PHP实现微信公众账号开发
  5. 用wcf实现带有“秒传”功能的网盘
  6. 防范 DDoS 攻击的 15 个方法
  7. C# 里窗体里(windows form)怎么播放音乐
  8. PTA的使用简介
  9. Python可视化TVTK库初使用
  10. Java初学习-常见单词
  11. 【C++】const & 指针
  12. Luogu P3239 [HNOI2015]亚瑟王
  13. 一些优秀的Python包
  14. Confluence 6 从其他备份中恢复数据
  15. 推荐一本写给IT项目经理的好书
  16. Java容器解析系列(6) Queue Deque AbstractQueue 详解
  17. day_5.22 py
  18. 通过脚本命令cacls提升某个用户都某路径的操作权限
  19. 『ACM C++』 PTA 天梯赛练习集L1 | 048-49
  20. HBase Scan,Get用法

热门文章

  1. Java 使用 Dbutils 工具类库 操作mysql
  2. 在sql server ide里数据修改数据
  3. oracle +plsql装完省略号不能点
  4. NOI2010~NOI2018选做
  5. PHP-从零开始使用Solr搜索引擎服务(上)
  6. 沉迷AC自动机无法自拔之:穿越广场 square
  7. 【CF710F】String Set Queries(二进制分组,AC自动机)
  8. 51nod 1483 化学变换 | 二进制 暴力
  9. python之旅:面向对象之继承与派生
  10. git的一些常见问题