Node概述
来源:互联网 发布:王鸥为什么被黑 知乎 编辑:程序博客网 时间:2024/05/23 12:00
Node:
Express -> webStorm ->提供了这个模板
npm:node的包管理工具 ->可以下载(发布)基于node的插件
可以使用前端的技术写服务端
模块化开发
模块化开发的标准:
AMD
CMD
Common.js
Node搭建本地服务器
服务器怎么去访问?通过主机地址加上端口号去访问localhost:3333,
在访问本地服务器的时候需要开启服务器->开启服务器的方法:node文件名
每一次在修改服务器里面内容的时候都需要重启服务器->停止服务器:control+c
require('http').createServer(function(req,res){ res.end('这是我的第一个node服务端工程')}).listen(3333)
使用express-generator创建node的工程
Bin/www是服务器的启动文件
Routes:写服务端API的地方
Localhost:3000/user
Localhost:3000/user/register
Localhost:3000/user/loginLocalhost:3000/index
Localhost:3000/message
App.js配置路由的地方
第一个客户端与服务端通讯的API
服务端:
/** *request:客户端发送给服务端的内容 *response:服务端发送给客户端的内容 */router.get('/register',function(request,response){ console.log(request); response.send({ code:200, message:'注册成功', data:{ id=100 } });})
客户端:
var HOST='http://localhost:3000/';var REGISTER='users.register';document.querySelector('.registerButton').onclick=function(){ var request=new XMLHttpRequest(); request.open('GET',HOST+REGISTER); request.onload=function(){ console.log(this.response); } request.send();}
注意:只要是不同端口或者不同主机地址互相访问数据会出现访问跨域
Corse(设置允许请求的主机地址origin)jsonP(json类型的数据交换格式)
阅读全文
0 0
- Node概述
- node.js概述
- Node.js1 概述
- 1.node.js 概述
- Node.js系列--Node.js概述
- Node.js的包概述
- 概述 - Node.js API 文档
- Node.js学习笔记(一)概述
- Node.js入门 - 概述和动手实验
- Node.js入门学习(概述)
- Node.js 学习笔记 —— 概述
- 一,Node.js的概述与安装
- node
- Node
- Node
- Node
- Node
- node
- Network Slimming
- JDBC入门详解
- 阿里巴巴面试java研发工程师实录
- 经济学十大原理
- 人工智能(AI)积累
- Node概述
- 欢迎使用CSDN-markdown编辑器
- JAVA
- HDU 5898 odd-even number (数位DP)
- Error:(21) Error: "rc_real_time_join_notification" is not translated in "en" (English) [MissingTrans
- html5shiv.js分析
- angular2学习(官方angular-cli跟写)
- 数据库三范式的理解
- 寻找最长公共子串