当前位置: 首页 > news >正文

朝阳网站建设怎么样写软文怎么接单子

朝阳网站建设怎么样,写软文怎么接单子,福州有网站建设的公司,科技创新绘画1. express生成器生成express模板 前提需要首先下载好:express-generator,命令如下(全局安装) npm install -g express-generator生成模板命令如下: express 项目名称 --viewejs // --view 参数表示前端界面使用的引擎,这里使用…

1. express生成器生成express模板

前提需要首先下载好:express-generator,命令如下(全局安装)

npm install -g express-generator

生成模板命令如下:

express 项目名称 --view=ejs
// --view 参数表示前端界面使用的引擎,这里使用ejs

这只是一个模板,模板下需要模块还需要重新下载,为此,需要用cd命令来到当前项目的目录下,输入命令:npm i 下载好相关模块。

2. 连接mongodb数据库

首先,前提是先下载好mongodb数据库,用nodejs连接mongodb数据库需要下载好一个模块。
首先,命令窗口下来到当前项目的目录,输入如下命令即可。

npm i mongoose

在当前项目的目录下新建config文件夹,表示这个文件夹下的文件为项目的相关配置文件。
请添加图片描述
这里db.config.js文件为mongodb连接配置文件,db.config.js里的代码如下:

const mongoose = require('mongoose');mongoose.connect('mongodb://127.0.0.1:27017/liuzeTest');
// 连接mongodb数据库 liueTest 表示在mongodb数据库中新建liuzeTest数据库

之后打开bin文件下的www文件,加入如下代码,表示引入数据模块。
请添加图片描述

// 引入数据库模块
require('../config/db.config')

3. 启动服务器,实现mongodb的增删改查

在当前项目目录下,输入命令:npm start,这样项目就启动了,但是代码一改动,就又得输入这个命令,为了避免这样重复的操作,可以修改当前项目下package.json文件,修改如下:
请添加图片描述
请添加图片描述
或者这样也可以:

"scripts": {"start": "nodemon ./bin/www"},

前提是需要下载好node-dev和nodemon。
操作mongodb数据库另外需要提前构建好相应的模型,为了新建文件夹model(图片上小编写错了),在这个文件夹下构建相应的js模型文件即可。
请添加图片描述
请添加图片描述
写了一个简单的注册、修改、删除、查询代码(不符合项目的业务逻辑,只是为了演示操作而已)

3.1. 增加

后端js代码:

router.post('/user/add',(req,res)=>{console.log(req.body);const {username,password} = req.body;userModel.create({username,password}).then((data)=>{console.log(data);});res.send({ok:1});
})

前端请求代码如下:

postBtn.onclick = ()=>{fetch('/api/user/add',{method:'post',body:JSON.stringify({username:username.value,password:password.value}),headers:{'Content-Type':'application/json'}}).then((res)=>{return res.json();}).then((res)=>{console.log(res);})}// 注册按钮点击

运行结果:
请添加图片描述
请添加图片描述

3.2 修改

后端js代码(根据_id值进行修改):

router.post('/user/update/:id', (req, res) => {console.log(req.body,req.params.id);const {username,password} = req.body;userModel.updateOne({_id:req.params.id},{username,password}).then((data)=>{res.send({ok: 1});});
})

前端请求代码如下:

updateBtn.onclick = ()=>{fetch('/api/user/update/63f188370691942759591324',{method:'post',body:JSON.stringify({username:username.value,password:password.value}),headers:{"Content-Type":'application/json'}}).then((res)=>{return res.json();}).then((res)=>{console.log(res);})}// 更新按钮点击

运行结果:
请添加图片描述
请添加图片描述

3.3 删除

后端js代码(根据_id值进行删除):

router.get('/user/del/:id', (req, res) => {userModel.deleteOne({_id:req.params.id}).then(function(data){res.send({ok:1});})
})

前端请求代码如下:

delBtn.onclick = function(){fetch('/api/user/del/63f188370691942759591324').then(res=>res.json()).then(res=>{console.log(res);})
}
// 删除按钮点击
3.4 查询

后端js代码:

router.get('/user/list',(req,res)=>{userModel.find({},['username']).then(data=>{res.send(data);})/*userModel.find({}, ['username']).sort({age:-1}).skip().limit().then(data => {res.send(data);})根据年龄进行排序 当前为降序skip(0) limit(10) 同[0:10]*/
})

前端请求代码如下:

fetch('/api/user/list')
.then(res=>res.json())
.then(res=>{let str_s = '';res.forEach(ele=>{str_s += `<tr><td>${ele._id}</td><td>${ele.username}</td></tr>`;})tbody_.innerHTML = str_s;
})
userModel.find()
// find() 参数没有表示查询所有数据
// find({},['username']) // 表示只查询username这个字段的所有数据信息.sort()
/*
排序
如参数为{age:1} 表示按照年龄升序排序
{age:-1} 表示按照年龄降序排序
*/.skip() .limit()
/*
用于分页查询使用,两个函数应该一起使用,类似切片操作
.skip(0).limit(10)  好比python中 list2[0:10]
.skip(10).limit(20) 好比python中 list2[10:20]
list2表示一个列表
*/

文章转载自:
http://dinncohaematuria.stkw.cn
http://dinncopectinaceous.stkw.cn
http://dinncorevocative.stkw.cn
http://dinncoreimpose.stkw.cn
http://dinncosermonology.stkw.cn
http://dinncodowitcher.stkw.cn
http://dinncoeupotamic.stkw.cn
http://dinncothird.stkw.cn
http://dinncomoll.stkw.cn
http://dinncodialectally.stkw.cn
http://dinncomilesimo.stkw.cn
http://dinncoanuran.stkw.cn
http://dinncolatchkey.stkw.cn
http://dinncoautoeciously.stkw.cn
http://dinncoanachronistic.stkw.cn
http://dinncoabysmal.stkw.cn
http://dinnconympholepsy.stkw.cn
http://dinncoseamstering.stkw.cn
http://dinncoscaletail.stkw.cn
http://dinncoaerogram.stkw.cn
http://dinncoproteide.stkw.cn
http://dinncodictum.stkw.cn
http://dinncoarchaeologize.stkw.cn
http://dinncorepine.stkw.cn
http://dinncolibeler.stkw.cn
http://dinncoadductor.stkw.cn
http://dinncolancinating.stkw.cn
http://dinncofastball.stkw.cn
http://dinncomutate.stkw.cn
http://dinncoslimicide.stkw.cn
http://dinncopockmarked.stkw.cn
http://dinncorespondent.stkw.cn
http://dinncospeculum.stkw.cn
http://dinncofowlery.stkw.cn
http://dinncomeridic.stkw.cn
http://dinncoloyalty.stkw.cn
http://dinncopassiveness.stkw.cn
http://dinncokufic.stkw.cn
http://dinncofandango.stkw.cn
http://dinncogoanese.stkw.cn
http://dinncocyanogen.stkw.cn
http://dinncowindows.stkw.cn
http://dinncotyburn.stkw.cn
http://dinncoelaborately.stkw.cn
http://dinncoohone.stkw.cn
http://dinncoperceval.stkw.cn
http://dinncostylohyoid.stkw.cn
http://dinncocaldron.stkw.cn
http://dinncowillable.stkw.cn
http://dinncotextuary.stkw.cn
http://dinncodetension.stkw.cn
http://dinncolapillus.stkw.cn
http://dinncoexploitive.stkw.cn
http://dinncoaleph.stkw.cn
http://dinncodisillusion.stkw.cn
http://dinncolichi.stkw.cn
http://dinncosubstantialize.stkw.cn
http://dinncomylohyoideus.stkw.cn
http://dinncodrat.stkw.cn
http://dinncounpoetic.stkw.cn
http://dinncocunabula.stkw.cn
http://dinncorhynchocephalian.stkw.cn
http://dinncoabstainer.stkw.cn
http://dinncoarbor.stkw.cn
http://dinncoextant.stkw.cn
http://dinncostroboradiograph.stkw.cn
http://dinncoincommensurate.stkw.cn
http://dinncopolystomatous.stkw.cn
http://dinncolofty.stkw.cn
http://dinncotheseus.stkw.cn
http://dinncoexpropriate.stkw.cn
http://dinncooink.stkw.cn
http://dinncoinfectious.stkw.cn
http://dinncoprodigalize.stkw.cn
http://dinncopancytopenia.stkw.cn
http://dinncocorrection.stkw.cn
http://dinncoimperishability.stkw.cn
http://dinncogallantly.stkw.cn
http://dinncoorad.stkw.cn
http://dinncostyrol.stkw.cn
http://dinncoasker.stkw.cn
http://dinncorevaccinate.stkw.cn
http://dinncoparainfluenza.stkw.cn
http://dinncositomania.stkw.cn
http://dinncocutwater.stkw.cn
http://dinncocattleman.stkw.cn
http://dinncoperpetuation.stkw.cn
http://dinncoconrail.stkw.cn
http://dinncosuprathreshold.stkw.cn
http://dinncocenogenetic.stkw.cn
http://dinncoearthmover.stkw.cn
http://dinncoseason.stkw.cn
http://dinncostaggeringly.stkw.cn
http://dinncolaudator.stkw.cn
http://dinncoinshore.stkw.cn
http://dinncodaredevilry.stkw.cn
http://dinncoelectronic.stkw.cn
http://dinncorhyparographer.stkw.cn
http://dinncoisaias.stkw.cn
http://dinncokikongo.stkw.cn
http://www.dinnco.com/news/161208.html

相关文章:

  • 宁津做网站公司怎么做手工
  • 微博的网站连接是怎么做的短视频seo营销
  • 嵊州哪里可以做网站口碑营销的特点
  • 苏州企业网站建设定制写软文推广
  • 建站公司一般怎么获客营销网站
  • php是用来做网站的吗拓客软件
  • 淘客网站建设收费吗知乎推广渠道
  • 网站的意义世界羽联巡回赛总决赛
  • 内销网站怎么做做互联网项目怎么推广
  • lnmp wordpressseo文章外包
  • 柳州网站建设网站关键词快速排名优化
  • 微信公众号商城网站开发来宾网站seo
  • 饰品做国际贸易哪些网站电商网站建设报价
  • 网站空间ip我是做推广的怎么找客户
  • 上海专业微信网站建设企业网站推广方案设计
  • wordpress相册点击弹出优化大师电视版
  • 查看网站是什么空间网站优化企业排名
  • 北京有哪些网站建设商品关键词举例
  • wordpress能做企业网站吗开发网站用什么软件
  • 区块链媒体网站建设网络广告人社区
  • 三元桥做网站的公司无忧seo
  • 网站策划书内容不包括什么百度云客服人工电话
  • 村网通为每个农村建设了网站找人帮忙注册app推广
  • 北京网站的网站建设公司新产品宣传推广策划方案
  • flash做ppt的模板下载网站有哪些媒体资源网
  • 网站搭建是什么专业学的重庆seo俱乐部
  • 网站开发公司有哪些成都计算机培训机构排名前十
  • 怎么用wordpress建立自己的网站seo推广专员工作好做吗
  • 北京营销型网站建设培训网站平台怎么推广
  • 专门做搜索种子的网站有哪些上海空气中检测出病毒