NodeJS 开篇 牛刀小试

一、Node&NPM的安装与配置

下载:https://nodejs.org/en/

V4.2.x LTS(9.75MB)——长期支持版,成熟可靠

V5.x.x Stable(9.71MB)——稳定版,最新特性

检测nodejs是否安装成功。打开cmd命令行 输入 node - v 显示当前版本号

检查npm是否安装,使用cmd命令行中键入 npm -v

二、简单例子

参考:http://jingyan.baidu.com/article/91f5db1b3e1f991c7f05e395.html

在安装目录下,创建www文件夹,创建文件hi.js

var http =require('http');
var listenPort=8011;//指定端口号

http.createServer(myServer).listen(listenPort);

function myServer(request,response)
{
    response.writeHead(200,{'Content-Type':'text/plain'});
    response.end('Hello World');//浏览器显示的内容
}

console.log('Server running!!!');//控制台显示的内容

打开cmd,切换到www文件夹,执行node hi.js

C:Program Files
odejswww>node hi.js

在浏览器中打开网址http://localhost:8011/,即可显示Hello World,注意关掉控制台则不能访问

三、VS插件NTVS

开源项目:https://github.com/Microsoft/nodejstools

下载地址: https://github.com/Microsoft/nodejstools/releases/tag/v1.1

原文地址:https://www.cnblogs.com/xcsn/p/5074796.html