您的位置:首页 > Web前端 > Node.js

NODE.JS的简单的例子

2016-07-18 12:07 417 查看
今天试了一下node.js 创建一个服务居然如此的简单,没忍住要分享给大家!


1.安装NODE.JS

brew cask install node


2.写一个简单的例子,保存为ex.js  





 


3.运行





 


4.看,hello dongdong






增强版(访问目录下的所有文件)

 

You can use Connect and ServeStatic with Node.js for this:

1.Install connect and serve-static with NPM

     $ npm install connect serve-static

2.Create server.js file with this content:

     var connect = require('connect');

     var serveStatic = require('serve-static');

     connect().use(serveStatic("/Users/jiangtao/site/ ")).listen(8080);

3.Run with Node.js

     $ node server.js

You can now go to http://localhost:8080/yourfile.html

 

把文件放在/Users/jiangtao/site/ 目录就好





 

示例文件下载:ex.js

server.js

参考:http://nodejs.org/

LikeBe
the first to like this

No labels

Edit
Labels



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: