学习node记录整理

1、查看版本 node --version ||| npm -v

2、安装模块 npm install express -g 全局安装

npm install express 局部安装

3、使用模块

var express = require('express');

var http = require('http');

http.createServer(function (request, response) {

// 发送 HTTP 头部

// HTTP 状态值: 200 : OK

// 内容类型: text/plain

response.writeHead(200, {'Content-Type': 'text/plain'});

// 发送响应数据 "Hello World"

response.end('Hello World\n');

}).listen(8888);

console.log('Server running at http://127.0.0.1:8888/');

4、卸载模块 npm uninstall express

5、更新模块 npm update express

6、node 终端交互 node启动

a = 1; b=a+1;

表达式

变量

Ctrl + C 退出终端交互

7、自定义模块

//hello.js function Hello() {     var name;     this.setName = function(thyName) {         name = thyName;     };     this.sayHello = function() {         console.log('Hello ' + name);     }; }; module.exports = Hello;

8、多模块

//SheHis.js

function She() {};

function His() {};

module.exports = {His,She};

//main3.js

var HH = require('./SheHis');

She = new HH.She();

She.setName('BYVoidShe');

She.sayHello();

His = new HH.His();

His.setName('BYVoidHis');

His.sayHello();

8、创建 http

9、获取参数

10、express框架

11、mysql

猜你喜欢

转载自blog.csdn.net/somdip/article/details/104799915