发布于 2016-12-25 06:06:23 | 82 次阅读 | 评论: 0 | 来源: 网友投递
Node.js 服务器端的JavaScript
Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台, 用来方便地搭建快速的 易于扩展的网络应用· Node.js 借助事件驱动, 非阻塞I/O 模型变得轻量和高效, 非常适合 运行在分布式设备 的 数据密集型 的实时应用
exports.Hello = function ( name ) {
console.log( "Hello " + name );
}
$ npm init
Package name: (hello) //模块名字,npm init会自动取当前目录名作为默认名字,这里不需要改,直接确认即可
Description: A example for write a module //模块说明
Package version: (0.0.0) 0.0.1 //模块版本号,这个大家按自己习惯来定就可以
Project homepage: (none) //模块的主页,如果有的话可以填在这里,也可以不填
Project git repository: (none) //模块的git仓库,选填。npm的用户一般都使用github做为自己的git仓库
Author name: Elmer Zhang //模块作者名字
Author email: (none) freeboy6716@gmail.com //模块作者邮箱
Author url: (none) http://www.elmerzhang.com //模块作者URL
Main module/entry point: (none) hello.js //模块的入口文件,我们这里是hello.js
Test command: (none) //测试脚本,选填
What versions of node does it run on? (~v0.5.7) * //依赖的node版本号,我们这个脚本可以运行在任何版本的node上,因此填 *
About to write to /home/elmer/hello/package.json
// 以下是生成的package.json文件内容预览
{
"author": "Elmer Zhang <freeboy6716@gmail.com> (http://www.elmerzhang.com)",
"name": "hello",
"description": "A example for write a module",
"version": "0.0.1",
"repository": {
"url": ""
},
"main": "hello.js",
"engines": {
"node": "*"
},
"dependencies": {},
"devDependencies": {}
}
Is this ok? (yes) //对以上内容确认无误后,就可以直接回车确认了
$ npm install hello/
hello@0.0.1 ./node_modules/hello
$ node
> var Hello = require('hello').Hello;
> Hello('world');
$ npm adduser
Username: elmerzhang
Password:
Email: freeboy6716@gmail.com