Node学习笔记----- Node.js

一、Node.js是什么

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.

1. 特性

Node.js 可以解析JS代码(没有浏览器安全级别的限制),提供很多系统级别的API,如:
· 文件的读写(File System)
· 进程的管理(Process)
· 网络通信(HTTP/HTTPS)
· ......

2. 举例

2.1 浏览器安全级别的限制

Ajax测试





    
    
    
    Document



    
browser-safe-sandbox

浏览器预览

browser-sync start --server --files **/* --directory

2.2 文件的读写(File System)

const fs = require('fs);
fs.readFile('./ajax.png','utf-8',(err,content)=>{
  console.log(content);
})

2.3 进程的管理(Process)

function main(arg) {
  console.log(arg);
}

main(process.argv.slice(2));

2.4 网络通信(HTTP/HTTPS)

const http = require('http');
http.createServer((req,res)=>{
  res.writeHead(200,{
    'contnt-type': 'text/plain'
  });
  res.write('hello node.js');
  res.end();
}).listen(3000);

你可能感兴趣的:(node.js)