node.js 基础篇
日志输出方式
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);
});
});
node.js 基础篇的更多相关文章
- Node.js基础与实战
Node.js基础与实战 Node.jsJS高级进阶 NODE原理与解析 REPL交互环境 模块与NPM Buffer缓存区 fs文件操作 Stream流 TCP&UDP 异步编程 HTTP& ...
- Node.js进阶篇-koa、钩子函数、websocket、嵌入式开发
代码地址如下:http://www.demodashi.com/demo/12932.html 一.简介 koa是由Express原班人马打造的,致力于成为一个更小.更富有表现力.更健壮的We ...
- node.js基础模块http、网页分析工具cherrio实现爬虫
node.js基础模块http.网页分析工具cherrio实现爬虫 一.前言 说是爬虫初探,其实并没有用到爬虫相关第三方类库,主要用了node.js基础模块http.网页分析工具cherri ...
- Node.js基础知识
Node.js入门 Node.js Node.js是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始.比较独特的是,Node.js会假设在POSIX环境下运行 ...
- 前端面试题目汇总摘录(JS 基础篇)
JS 基础 JavaScript 的 typeof 返回那些数据类型 object number function boolean undefined string typeof null; // o ...
- Node.js学习准备篇
这里写个Node.js 准备篇包含内容有node.js 的安装,命令行运行node.js 文件,使用webStrom 编写 node.js 时有提示功能,并用webStrom 运行 Node.js 其 ...
- NodeJs>------->>第三章:Node.js基础知识
第三章:Node.js基础知识 一:Node.js中的控制台 1:console.log.console.info 方法 console.log(" node app1.js 1> ...
- 10慕课网《进击Node.js基础(一)》初识promise
首先用最简单的方式实现一个动画效果 <!doctype> <html> <head> <title>Promise animation</titl ...
- 进击Node.js基础(二)
一.一个牛逼闪闪的知识点Promise npm install bluebird 二.Promise实例 ball.html <!doctype> <!DOCTYPE html> ...
随机推荐
- Word Ladder II Graph
Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...
- SpringBoot(十一)_springboot热部署
在开发中,后台修改了代码就要重新启动服务,很是费劲,现在我们可以让SpringBoot自动编译 热启动就需要用到我们在一开始引入的另外一个组件:devtools.它是 Spring Boot 提供的一 ...
- Tomcat 总体结构
一.Tomcat 总体结构 1.Server(服务器)是Tomcat构成的顶级构成元素,所有一切均包含在Server中,Server的实现类StandardServer可以包含一个到多个Service ...
- eclipse中添加配置文件夹config
1. 在项目上右键->Build path->Configure Build Path->Source下的Add Folder,如图 2. 在弹出框中,Create New Fold ...
- 环形buffer缓冲区
#include <stdio.h> #include <string.h> #include <malloc.h> struct CircleBuf { char ...
- BZOJ3329 Xorequ(数位dp+矩阵快速幂)
显然当x中没有相邻的1时该式成立,看起来这也是必要的. 于是对于第一问,数位dp即可.第二问写出dp式子后发现就是斐波拉契数列,矩阵快速幂即可. #include<iostream> #i ...
- 关于dismissViewControllerAnimated值得注意的一点(deinit)
在使用dismissViewControllerAnimated退出当前视图的时候,理论上,该视图对象就会被清除了, 也就是说会进去当前类的析构函数deinit里面.但是有时候会发现,dismiss之 ...
- PHP是什么?
PHP是什么? PHP是一门后端动态解释型计算机高级语言,一般用来编写或者生成动态网页,主要负责数据的处理与渲染.(这里是指用PHP嵌入网页里面的形式,现在可以直接用一些JS的框架去渲染网页数据了,P ...
- as, idea 出现 Gradle's dependency cache may be corrupt 错误分析
问题: Error:Failed to open zip file.Gradle's dependency cache may be corrupt (this sometimes occurs af ...
- android 布局的两个属性 dither 和 tileMode
tileMode(平铺)tileMode(平铺) 的效果类似于 让背景小图不是拉伸而是多个重复(类似于将一张小图设置电脑桌面时的效果) dither(抖动) Dither(图像的抖动处理,当每个颜色值 ...