NodeJS后台
NodeJS后台
后台:
1.PHP
2.Java
3.Python
优势
1.性能
2.跟前台JS配合方便
3.NodeJS便于前端学习



1.切换盘符 e:
2.改变目录 cd 目录名
3.执行程序 node xxx.js
const http = require('http');
http.createServer(function(req, res){
// 前台响应
res.write("dashucoding");
res.end();
});
// 监听
// 端口
server.listen(123);
nodeJS——服务器
http——协议
request 请求
response 响应

文件操作:fs——File System
http——模块
异步 vs 同步
异步——多个操作可以同时进行,前一次的操作没完事,后一次也能开始
同步——一次一个
const fs=require('fs');
// readFile(文件名,回调函数)
readFile(文件名, function (err, data){})
writeFile(文件名, 内容, function (err){})
oBtn.onclick=function (){
alert('a');
};
alert('b');



const http=require('http');
const fs=require('fs');
var server=http.createServer(function (req, res){
//req.url=>'/index.html'
//读取=>'./www/index.html'
// './www'+req.url
var file_name='./www'+req.url;
fs.readFile(file_name, function (err, data){
if(err){
res.write('404');
}else{
res.write(data);
}
res.end();
});
});
server.listen(8080);
const fs=require('fs');
//writeFile(文件名, 内容, 回调)
fs.writeFile("bbb.txt", "dda", function (err){
console.log(err);
});
const fs=require('fs');
//readFile(文件名, 回调函数)
fs.readFile('aaa.txt', function (err, data){
if(err){
console.log('读取失败');
}else{
console.log(data.toString());
}
});
//fs.writeFile
buffer类用于二进制数据的存储提供一个缓存区
settimeout函数用于指定时间到达执行一个指定函数,指定方法为从当前时刻之后多少毫秒
cleartimeout函数用于取消在settimeout函数内指定的函数的执行
var http = require('http');
http.createServer(function(req,res){
res.writeHead(200, {'Content-Type':'text/html'});
res.write('<head><meta charset="utf-8"/></head>');
res.end('你好\n');
}).listen(1234,"127.0.0.1");
var http=require('http');
http.createServer(function(req,res){
// 回调函数中的代码
})

//一行
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
//两行
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;


小程序简单实现双击事件
data = {
tabBar: [],
// recommendList: [],
floorList: [],
banners: [],
currentIndex: 1,
canGetCoupon: false,
// 触摸开始时间
touchStartTime: 0,
// 触摸结束时间
touchEndTime: 0,
// 最后一次单击事件点击发生时间
lastTapTime: 0
}
getCoupon: function (e) {
let that = this
if (that.touchEndTime - that.touchStartTime < 350) {
// 当前点击的时间
let currentTime = e.timeStamp
let lastTapTime = that.lastTapTime
// 更新最后一次点击时间
that.lastTapTime = currentTime
// 如果两次点击时间在300毫秒内,则认为是双击事件
if (currentTime - lastTapTime < 300) {
// 成功触发双击事件时,取消单击事件的执行
// clearTimeout(that.lastTapTimeoutFunc)
getCoupon({}).then(res => {
this.canGetCoupon = false
})
wx.showToast({
title: '优惠券领取成功',
duration: 3000
})
}
}
doubleClick(e){
//e.timeStamp:当前点击时的毫秒数;
// this.touchStartTime: 储存上一次点击时的毫秒数,默认0
if (e.timeStamp - this.touchStartTime < 300){
双击,进入
}
this.touchStartTime = e.timeStamp;
单击
}
/*
if ((e.timeStamp - this.touchStartTime) < 100) {
getCoupon({}).then(res => {
this.canGetCoupon = false
})
wx.showToast({
title: '领取成功',
icon: 'none',
duration: 3000
})
}
this.touchStartTime = e.timeStamp
*/
// 触摸开始时间
touchStartTime: 0,
// 触摸结束时间
touchEndTime: 0,
// 最后一次单击事件点击发生时间
lastTapTime: 0,
// 单击事件点击后要触发的函数
lastTapTimeoutFunc: null,
/// 双击
doubleTap: function(e) {
var that = this
// 控制点击事件在350ms内触发,加这层判断是为了防止长按时会触发点击事件
if (that.touchEndTime - that.touchStartTime < 350) {
// 当前点击的时间
var currentTime = e.timeStamp
var lastTapTime = that.lastTapTime
// 更新最后一次点击时间
that.lastTapTime = currentTime
// 如果两次点击时间在300毫秒内,则认为是双击事件
if (currentTime - lastTapTime < 300) {
console.log("double tap")
// 成功触发双击事件时,取消单击事件的执行
clearTimeout(that.lastTapTimeoutFunc);
wx.showModal({
title: '提示',
content: '双击事件被触发',
showCancel: false
})
}
}
},















控制台,全局作用域,全局变量和全局函数,事件处理机制以及事件环机制,怎么使用node.js框架中提供的调试工具。
请点赞!因为你的鼓励是我写作的最大动力!
吹逼交流群:711613774

NodeJS后台的更多相关文章
- linux中nodejs后台运行工具forever
forever让nodejs应用后台执行 命令如下: forever start './bin/www' nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让no ...
- nodejs 后台服务启动
最近一个项目微信小程序,需要写个小型的后端程序处理聊天通讯记录保存,主要是功能是组建群聊天室,所以用node写了个websocket服务... 但是终端连接到服务器,运行 node server.js ...
- nodejs后台集成富文本编辑器(ueditor)
1 下载ueditor nodejs版本 2 复制public目录下面的文件 到项目静态资源public文件夹下 3 在项目根目录创建ueditor文件夹 要复制进来的内容为 4 在根目录的 uedi ...
- 转)nodejs后台启动方式PM2
如果直接通过node app来启动,如果报错了可能直接停在整个运行,supervisor感觉只是拿来用作开发环境的.再网上找到pm2.目前似乎最常见的线上部署nodejs项目的有forever,pm2 ...
- forever让nodejs后台运行
nodejs一般是当成一条用户命令执行的,当用户断开客户连接,运用也就停了,很烦人.如何让nodejs应用当成服务,在后台执行呢? 最简单的办法: $ nohup node app.js 但是,for ...
- nodejs后台向后台get请求
1 前言 有时在nodejs写的服务端某方法需要向服务端另一个接口发送get请求,可以使用第三方库,然后直接使用即可,此文章只是用来记录使用 2 方法 2.1 get 请求 //1. Install ...
- Nodejs后台管理员登录实例
思路: 直接访问后台页面时如果无session则跳转到404 当在登录页的表单提交时对数据库进行匹配,匹配成功生成session,否则提示用户名或密码错误 准备页面 :后台首页.登录页.404页, 步 ...
- nodejs后台启动
可避免关闭窗口,程序就关闭,可在后台运行 安装forever包,一般用于服务器,调试环境可不安装 npm install forever -g 启动方式如图: 查询后台运行哪些程序 forever l ...
- nodejs后台运行的方法
nohup node ***.js & 这种方法可以,但存在你无法查询日志等问题 在SSH里另一个有效的方法是screen命令. [转]http://www.9usb.net/201002/l ...
随机推荐
- Hystrix 用法及注解用法
一.hystrix参数使用方法 通过注解@HystrixCommand的commandProperties去配置,如下就是hystrix命令超时时间命令执行超时时间,为1000ms和执行是不启用超时 ...
- 洛谷 P1217 回文质数
洛谷 P1217 回文质数 链接 https://www.luogu.org/problem/P1217 题目 题目描述 因为 151 既是一个质数又是一个回文数(从左到右和从右到左是看一样的),所以 ...
- 在论坛中出现的比较难的sql问题:18(字符合并 整数解析星期几)
原文:在论坛中出现的比较难的sql问题:18(字符合并 整数解析星期几) 最近,在论坛中,遇到了不少比较难的sql问题,虽然自己都能解决,但发现过几天后,就记不起来了,也忘记解决的方法了. 所以,觉得 ...
- nodejs中使用mongodb
/** * 使用mongodb存储数据 * 1 首先安装mongodb nodejs插件 npm install mongodb --save-dev * 2 安装express (非必须) * * ...
- 目标进程已退出,但未引发 CoreCLR 启动事件
目标进程已退出,但未引发 CoreCLR 启动事件.请确保将目标进程配置为使用 .NET Core.如果目标进程未运行 .NET Core,则发生这种情况并不意外 解决:更新SDK版本
- weui中的picker滑动报错
html { touch-action: none; } 在页面插入上述代码即可解决
- javascript中bind()、call()、apply()的使用
一直以来对bind().apply().call()这三个方法都模模糊糊的,现在有时间详细的看看这三个方法,并记录下来. bind() 参考文档:https://developer.mozilla.o ...
- 如何通过wlst部署应用程序到weblogic12c上
适用版本 Oracle WebLogic Server - Version 10.3 and laterInformation in this document applies to any plat ...
- [dev][ipsec][distributed] strongswan如何做热迁移/高可用/High Availability
问题描述: 原生的基于kernel 的 strongswan 如何做高可用,HA,High Availability 问题分析: 基于我们已知的,ipsec,strongswan的知识.问题分解如下: ...
- sql的时间格式
sql中的时间格式转换主要有:date_format函数,str_to_date函数 1. 首先选择一个数据库 use db_name; 2. 显示当前时区的时间: SELECT NOW(); 3. ...