Node单词大全
NodeJS单词大全
0~9
node:节点,茎节;(根或枝上的)瘤,节,结,结点;
event:事件;
driven:驱动;奋发努力的;发愤图强的;受…影响的;由…造成的,驾驶,开车;驾车送(人);拥有(或驾驶)…汽车
read:v.读到; 识字;阅读;读懂;读;朗读;查阅到 n. 阅读;读书;好的(或有意思等的)读物;好书(或文章等) adj. 博学的;熟知的;精通的
file:文件,文件夹;卷宗;(计算机的)文件;档案 v. 把(文件等)归档;提起(诉讼);提出(申请);送交(备案);发送(报道给报社)
require:需要;依靠;依赖;使做(某事);使拥有(某物);(尤指根据法规)规定
let fs = require('fs');
fs.readFile('./01_Node简介.js', function (err, data) {}
fs.writeFile('./03_你好.md', '大家好,给大家介绍一下,我是Node.js', function (err) {}
let http = require('http');
10~19
let server = http.createServer();
server.on('request', function (request, response) {}
request.url:请求路径;
request.socket.remoteAddress:地址号;
request.socket.remotePort:端口号;
response.setHeader('Content-Type', 'text/plain; charset=utf-8');
response.write('hello server');
response.end();
server.listen(8000, function () { console.log('服务器启动成功,8000端口正在监听中,通过http://127.0.01:8000来访问服务器 ...');
server:服务器;
20~29
request:请求;
response:响应;
os:(计算机)操作系统;(国防部/国防系统管理学院)开放系统;观察中队(Observation Squadron)
let template = require('art-template');
let resData = template.render(data.toString(), {替换对象})
global:全局的,全球的;
Express:表示;表达;表露;表达(自己的思想感情);显而易见;不言自明 adj. 特快的;快速的;快递的;用快递寄送的;提供快递服务的 adv. 使用快速服务 n. 特快列车;快件服务;快递服务;快运服务
arr.find(function(item,index,arr){ return XXX})
arr.findIndex(function(item,index,arr){ return XXX})
MongoDB:数据库类型;
30~39
mongoose:第三包,使用MongoDB数据库的相关接口
Schema:模式;图式;架构;方案;基模;
"mongo"命令默认连接本机的开启的MongoDB服务
"exit"命令断开连接的MongoDB服务
"show dbs" => 查看所有数据库
"db" => 查看当前操作的数据库
"use 数据库名称" => 切换到指定的数据库(如果没有则自动新建)
"db.属性名.insertOne({数据})" => 插入数据
"show collections" => 显示所有表(表是一种存储联系,例:students,teachers,people,famlae,mlae)
"db.属性名.find()" => 查找并显示此属性储存的数据
40~49
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/text', { useMongoClient: true });
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: '喵喵王' });
kitty.save(function (err) { if (err) { console.log(err); } else { console.log('写入成功'); } });
var Schema = mongoose.Schema;
mongoose.connect("mongodb://localhost/itcast");
var blogSchema = new Schema({ title: String,
var Blog = mongoose.model('Blog', blogSchema);
var b1 = new Blog({ title: '叫我第一名', author: "小男孩" });
50~59
b1.save((err, ret) => {});
Blog.find(function (err, data) {});
Blog.find({author:"小男孩"},function (err, data) {});
Blog.findOne({author:"小男孩"},function (err, data) {});
Blog.findByIdAndUpdate('60a482a3744a6232a8755b41',{author:"小女孩"},function (err, data) {});
Blog.findByIdAndRemove("60a488fe22e3583ac8766b0c", function (err) {}
Blog.findOneAndRemove({ author: '小男孩' }, function (err) {});
Blog.remove({ author: '小男孩' }, function (err) {});
promise:v. 承诺;许诺;答应;保证;使很可能;预示 n. 诺言;许诺;承诺;获得成功的迹象,吉兆,迹象;
function Pro_obj(){ return new Promise((resolve,reject)=>{resolve(data_XX)}); } new Promise((resolve,reject)=>{ resolve(data_XX)).then((data)=>{return Pro_obj(data)}).then((data)=>{return Pro_obj()}).then((data)=>{return Pro_obj()}).then((data)=>{console.log(data,"then链式调用结束")}) ;
60~69
var express = require("express");
var path = require("path");
app.use("/public/", express.static(path.join(__dirname, "./public/")));
app.use("/node_modules/", express.static(path.join(__dirname, "./node_modules/")));
app.engine('html', require("express-art-template")); app.set("views", __dirname);
app.get('/', function (req, res) { res.render("./31_index.html"); });
app.listen(5000, function () { console.log("running......"); });
express-session:数据加密第三方包
app.use({ secret: "itcast", resave: false, saveUninitialized: false
request.session.foo = "bar"
70~79
request.session.foo
request.session.XXX=null 或 delete(request.session.XXX)
app.use(function (req, res, next) { next(err);
app.use(function (err, req, res, next) { console.log(err,err.message)}
router:路由;
var express = require('express');
var fs = require('fs');
var Student = require('./student.js');
var router = express.Router();
router.get('/', function (req, res) {}
80~89
res.redirect('/');
module.exports = router;
app.engine('html', require('express-art-template')); app.set('view options', { debug: process.env.NODE_ENV !== 'production' }); app.set("views", path.join(__dirname, "./views/"));
app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json());
app.use(router)
案例流程:https://blog.csdn.net/Java_53/article/details/117332376
@沉木 2021/5/27
@沉木