01. Node js Hello world

01. Node js Hello world

环境安装

官网http://nodejs.org/node

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.浏览器

上面那句话来自官网;自己就是一个网络应用;不像有些是本地应用网络

进入官网,看到install 按钮直接点去,就会自动去下载;下载完后自动去安装;app

  • 确保 node 命令在Path 目录下

安装结果

  • 在terminal 中运行ui

    node -v

    看到 v0.10.26 相似的结果就说明安装成功命令行

写个Hello World

  1. hello_world.jsscala

    var http = require('http')
     http.createServer(function(req, res){
     	res.writeHead(200,{'Content-Type':'text/plain'});
     	res.end('Hello world\n');
     }).listen(1337,'127.0.0.1');
     console.log('Server running at http://127.0.0.1');
  2. 运行code

    node hello_world.js
  3. 浏览器输入orm

    http://127.0.0.1:1337
  4. 真正的Hello world 在hello_world.js中以下:ip

    console.log('Hello world')

    运行:

    node hello_world.js
  5. 其实还有更简单的

    直接在終端输入:

    node

    就出现命令行界面, 直接输入

    console.log('Hello world')

以上是入门,基础;

相关文章
相关标签/搜索