Nodejs+express+ejs简单使用实例代码

前端之家收集整理的这篇文章主要介绍了Nodejs+express+ejs简单使用实例代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

前几天主要看了express,今天开始接触ejs,jade还是不想看了,O(∩_∩)O哈哈~

var app = express();

app.engine('html',ejs.renderFile);

app.set("view engine","html");

app.use(function(req,res,next) {
res.locals.userinfo = {
userid : 123,username : "ladeng"
};
next();
});

app.get("/",function(req,res) {
var list = [1,2,4,5,7,8];
res.render("sdf",{title : "我是NodeJs测试",list : list});
});

app.listen(8188);

console.log("服务器运行中");

上面的代码是js代码,我是用的sublime text开发的,ejs的扩展名太坑了,所以就转了一下。

<Meta charset="UTF-8"> <%=title%>@H_<a href="/tag/404/" target="_blank" class="keywords">404</a>_11@ </head> <body> <%= userinfo.username%> <ul> <%for(var i = 0 ; i < list.length ; i++) {%> <li><%= list[i]%></li> <%}%> </ul> </body> </html></pre> </div> <p>这个是html的<a href="/tag/daima/" target="_blank" class="keywords">代码</a>,跟.net里的语法还是很像的,用起来很简单,这也是我选择ejs的原因,据说速度不如jade,who care </p> <p>以上就是本文的全部<a href="/tag/neirong/" target="_blank" class="keywords">内容</a>,希望对大家的学习有所帮助,也希望大家多多<a href="/tag/zhichi/" target="_blank" class="keywords">支持</a>编程之家。</p></div> <div class="topcard-tags"><a href="/tag/ejs/" class="tag_link" target="_blank">ejs</a><a href="/tag/express/" class="tag_link" target="_blank">express</a><a href="/tag/expressp/" class="tag_link" target="_blank">express</a><a href="/tag/pexpress/" class="tag_link" target="_blank">express</a><a href="/tag/nodejs/" class="tag_link" target="_blank">nodejs</a><a href="/tag/pnodejs/" class="tag_link" target="_blank">nodejs</a><a href="/tag/nodejsp/" class="tag_link" target="_blank">nodejs</a></div> <ul class="list-group"> <li class="list-group-item"><a href="/express/36361.html" title="利用express启动一个server服务的方法">上一篇:利用express启动一个server服务的方</a><a href="/express/36345.html" title="Express使用html模板的详细代码" class="text-muted pull-right">下一篇:Express使用html模板的详细代码</a> </li> </ul> </div> </div> </div> <!-- row end --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-4605373693034661" data-ad-slot="9144498553"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script></div> </div> </div> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <div class="title"><h1>猜你在找的Express 相关文章</h1></div> <div class="list_con"> <a href="/express/454310.html" title="Express中使用模板引擎"><div class="title">Express中使用模板引擎</div> <div class="summary">在express中设置模板引擎。 定义模板引擎varexpress=require(\'express\'...</div> <time class="summary">作者:前端之家 时间:2019-04-16</time> </a> </div> <div class="list_con"> <a href="/express/422704.html" title="【nodejs】Express"><div class="title">【nodejs】Express</div> <div class="summary">一、起步 ---- http://www.alloyteam.com/2015/03/sexpressmysql/ 二、理解 ---- 1.MVC Mo...</div> <time class="summary">作者:前端之家 时间:2019-04-05</time> </a> </div> <div class="list_con"> <a href="/express/422516.html" title="Express+supervisor快速搭建热更新应用服务器"><div class="title">Express+supervisor快速搭建热更新应用服务器</div> <div class="summary">##准备工作: 1.安装nodejs 2.安装express npm install express -g 3.安装express应用生成...</div> <time class="summary">作者:前端之家 时间:2019-04-12</time> </a> </div> <div class="list_con"> <a href="/express/403271.html" title="Node.js基于Express框架搭建一个简单的注册登录Web功能"><img class="lazy" src="/images/np.jpg" data-original="/res/2019/04-01/23/522d0127f2419b2037dc75db4b353fcf.png" title="" width="160" height="90" style="float:right;margin-left:30px;display:none;" /><div class="title">Node.js基于Express框架搭建一个简单的注册登录Web功能</div> <div class="summary">这个小应用使用到了node.js  bootstrap  express  以及数据库的操作 :使用mongoose对象...</div> <time class="summary">作者:前端之家 时间:2019-04-01</time> </a> </div> <div class="list_con"> <a href="/express/238709.html" title="使用express.js框架一步步实现基本应用以及构建可扩展的web应用"><img class="lazy" src="/images/np.jpg" data-original="/res/2019/03-18/21/dbb0099ff49ad35c5dc2d59decb372ff.png" title="" width="160" height="90" style="float:right;margin-left:30px;display:none;" /><div class="title">使用express.js框架一步步实现基本应用以及构建可扩展的web应用</div> <div class="summary">最近过年在家有点懈怠,但是自己也不断在学习新的前端技术,在家琢磨了express.js的web框架...</div> <time class="summary">作者:前端之家 时间:2019-03-18</time> </a> </div> <div style="border-bottom: 1px solid #f4f4f4;margin-top:20px;"> <ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-fr-2o+fp-dx-wx" data-ad-client="ca-pub-4605373693034661" data-ad-slot="4561116489"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div><div class="list_con"> <a href="/express/73944.html" title="express 安装和运行"><div class="title">express 安装和运行</div> <div class="summary">1.npm install -g express-generator2.进入服务目录(自己定义的文件夹,或者express Myapp...</div> <time class="summary">作者:前端之家 时间:2019-02-27</time> </a> </div> <div class="list_con"> <a href="/express/73410.html" title="Node.js 蚕食计划(三)—— Express 启航"><div class="title">Node.js 蚕食计划(三)—— Express 启航</div> <div class="summary">如果看过上一篇《Node.js 蚕食计划》,就会发现手动搭建一个 web 服务器还是比较繁琐而 ex...</div> <time class="summary">作者:前端之家 时间:2019-02-18</time> </a> </div> <div class="list_con"> <a href="/express/73409.html" title="Node.js 蚕食计划(四)—— Express + SQL Server 搭建电影网站"><img class="lazy" src="/images/np.jpg" data-original="/res/2019/02-18/17/912d39ebc12380eecc5a76d7c3e98b18.gif" title="" width="160" height="90" style="float:right;margin-left:30px;display:none;" /><div class="title">Node.js 蚕食计划(四)—— Express + SQL Server 搭建电影网站</div> <div class="summary">前段时间在慕课网上看了 scott 大神的《node+mongodb建站攻略》课程,按照自己的思路做了一...</div> <time class="summary">作者:前端之家 时间:2019-02-18</time> </a> </div> <div class="list_con"> <a href="/express/72514.html" title="Regular Expressions --正则表达式官方教程"><div class="title">Regular Expressions --正则表达式官方教程</div> <div class="summary">http://docs.oracle.com/javase/tutorial/essential/regex/index.htmlThis lesson explain...</div> <time class="summary">作者:前端之家 时间:2019-02-12</time> </a> </div> <div class="list_con"> <a href="/express/72497.html" title="Regular Expressions in Grep Command with 10 Examples --reference"><div class="title">Regular Expressions in Grep Command with 10 Examples --reference</div> <div class="summary">Regular expressions are used to search and manipulate the text, based on the pattern...</div> <time class="summary">作者:前端之家 时间:2019-02-12</time> </a> </div> <div style="border-bottom: 1px solid #f4f4f4;margin-top:20px;"> <ins class="adsbygoogle" style="display:block" data-ad-format="fluid" data-ad-layout-key="-fr-2o+fp-dx-wx" data-ad-client="ca-pub-4605373693034661" data-ad-slot="4561116489"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div></div> </div> </div> </div> <!-- left end--> <!-- right --> <div class="col-sm-12 col-md-12 col-lg-3"> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <label class="main-content-label ">编程分类</label> <div class="cate mt-20"><a href="/html/" title="HTML">HTML</a><a href="/html5/" title="HTML5">HTML5</a><a href="/js/" title="JavaScript">JavaScript</a><a href="/css/" title="CSS">CSS</a><a href="/jquery/" title="jQuery">jQuery</a><a href="/bootstrap/" title="Bootstrap">Bootstrap</a><a href="/angularjs/" title="Angularjs">Angularjs</a><a href="/typescript/" title="TypeScript">TypeScript</a><a href="/vue/" title="Vue">Vue</a><a href="/dojo/" title="Dojo">Dojo</a><a href="/json/" title="Json">Json</a><a href="/electron/" title="Electron">Electron</a><a href="/nodejs/" title="Node.js">Node.js</a><a href="/extjs/" title="extjs">extjs</a><a href="/express/" title="Express ">Express </a><a href="/xml/" title="XML">XML</a><a href="/es6/" title="ES6">ES6</a><a href="/ajax/" title="Ajax">Ajax</a><a href="/flash/" title="Flash">Flash</a><a href="/unity/" title="Unity">Unity</a><a href="/react/" title="React">React</a><a href="/flex/" title="Flex">Flex</a><a href="/antdesign/" title="Ant Design">Ant Design</a><a href="/webfrontend/" title="Web前端">Web前端</a><a href="/weapp/" title="微信小程序">微信小程序</a><a href="/wxmp/" title="微信公众号">微信公众号</a><div class="clearfix"></div> </div> </div> </div> </div> <!-- row end --> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <!-- f2er-rightads --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4605373693034661" data-ad-slot="7756441254" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> <!-- row end --> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <label class="main-content-label ">最新文章</label> <ul class="n-list"><li><a href="/express/454310.html" title="Express中使用模板引擎" target="_blank">• Express中使用模板引擎</a></li> <li><a href="/express/422704.html" title="【nodejs】Express" target="_blank">• 【nodejs】Express</a></li> <li><a href="/express/422516.html" title="Express+supervisor快速搭建热更新应用服务器" target="_blank">• Express+supervisor快速搭</a></li> <li><a href="/express/403271.html" title="Node.js基于Express框架搭建一个简单的注册登录Web功能" target="_blank">• Node.js基于Express框架搭</a></li> <li><a href="/express/238709.html" title="使用express.js框架一步步实现基本应用以及构建可扩展的web应用" target="_blank">• 使用express.js框架一步步</a></li> <li><a href="/express/191610.html" title="[Node.js]Express web框架" target="_blank">• [Node.js]Express web框架</a></li> <li><a href="/express/73944.html" title="express 安装和运行" target="_blank">• express 安装和运行</a></li> <li><a href="/express/73410.html" title="Node.js 蚕食计划(三)—— Express 启航" target="_blank">• Node.js 蚕食计划(三)—</a></li> <li><a href="/express/73409.html" title="Node.js 蚕食计划(四)—— Express + SQL Server 搭建电影网站" target="_blank">• Node.js 蚕食计划(四)—</a></li> <li><a href="/express/72514.html" title="Regular Expressions --正则表达式官方教程" target="_blank">• Regular Expressions --正</a></li> </ul> </div> </div> </div> <!-- row end --> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <label class="main-content-label ">热门标签 <span class="pull-right tx-12"> <a href="/all" target="_blank">更多 ►</a></span> </label> <div class="topcard-tags"><a href="/tag/guanbiyangao/" title="关闭广告" target="_blank">关闭广告</a><a href="/tag/danduheaders/" title="单独headers" target="_blank">单独headers</a><a href="/tag/fengzhuangdaima/" title="封装代码" target="_blank">封装代码</a><a href="/tag/tishicuowu/" title="提示错误" target="_blank">提示错误</a><a href="/tag/zhengshuzhengze/" title="整数正则" target="_blank">整数正则</a><a href="/tag/fei0kaitou/" title="非0开头" target="_blank">非0开头</a><a href="/tag/tiaoye/" title="跳页" target="_blank">跳页</a><a href="/tag/chuyema/" title="出页码" target="_blank">出页码</a><a href="/tag/antdtable/" title="antd table" target="_blank">antd table</a><a href="/tag/tishiURLweizhuce/" title="提示URL未注册" target="_blank">提示URL未注册</a><a href="/tag/gongzhonghaozhifu/" title="公众号支付" target="_blank">公众号支付</a><a href="/tag/vuehashmoshi/" title="vue hash模式" target="_blank">vue hash模式</a><a href="/tag/iSlider/" title="iSlider" target="_blank">iSlider</a><a href="/tag/chepaijianpan/" title="车牌键盘" target="_blank">车牌键盘</a><a href="/tag/xunhuantupian/" title="循环图片" target="_blank">循环图片</a><a href="/tag/echartsshuangzhexian/" title="echarts 双折线" target="_blank">echarts 双折</a><a href="/tag/zuoyoubuju/" title="左右布局" target="_blank">左右布局</a><a href="/tag/DllPlugin/" title="DllPlugin" target="_blank">DllPlugin</a><a href="/tag/duixiangchuangjian/" title="对象创建" target="_blank">对象创建</a><a href="/tag/daziyouxi/" title="打字游戏" target="_blank">打字游戏</a><a href="/tag/quanxuan/" title="圈选" target="_blank">圈选</a><a href="/tag/lianglan/" title="两栏" target="_blank">两栏</a><a href="/tag/yunhanshu/" title="云函数" target="_blank">云函数</a><a href="/tag/mengban/" title="蒙版" target="_blank">蒙版</a><a href="/tag/ES2020/" title="ES2020" target="_blank">ES2020</a><a href="/tag/chuchuang/" title="橱窗" target="_blank">橱窗</a><a href="/tag/wufenggundonglunbo/" title="无缝滚动轮播" target="_blank">无缝滚动轮播</a><a href="/tag/sekuaipengzhuang/" title="色块碰撞" target="_blank">色块碰撞</a><a href="/tag/zujianxiaohui/" title="组件销毁" target="_blank">组件销毁</a><a href="/tag/wendangcaozuo/" title="文档操作" target="_blank">文档操作</a></div> </div> </div> </div> <!-- row end --> <!-- row --> <div class="row row-sm"> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <!-- f2er-rightads --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4605373693034661" data-ad-slot="7756441254" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> </div> <!-- row end --> </div> <!-- right end --> </div> </div> <footer id="footer"> <div class="container"> <div class="row hidden-xs"> <dl class="col-sm-6 site-link"> <dt>最近更新</dt><dd><a href="/win11/1005328.html" title="小米手机重装系统价格多少?专业维修服务详解" target="_blank">· 小米手机重装系统价格多少?专业维修服务详解</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005327.html" title="手把手教你重装电脑系统,让你的电脑焕然一新!" target="_blank">· 手把手教你重装电脑系统,让你的电脑焕然一新!</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005326.html" title="教你一步步重装XP系统,让你的电脑重获新生" target="_blank">· 教你一步步重装XP系统,让你的电脑重获新生</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005325.html" title="从备份到上网:一步步教你重装电脑系统" target="_blank">· 从备份到上网:一步步教你重装电脑系统</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005324.html" title="Sony笔记本电脑一键重装系统详细图文教程" target="_blank">· Sony笔记本电脑一键重装系统详细图文教程</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005323.html" title="Lenovo笔记本重装系统超详细教程,小白也能轻松上手" target="_blank">· Lenovo笔记本重装系统超详细教程,小白也能轻松...</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005322.html" title="联想笔记本一键重装Win10系统详细教程" target="_blank">· 联想笔记本一键重装Win10系统详细教程</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005321.html" title="电脑系统故障无需愁,专业维修店帮你重装旧貌换新颜" target="_blank">· 电脑系统故障无需愁,专业维修店帮你重装旧貌换新...</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005320.html" title="联想笔记本一键重装Win10系统图文教程,小白也能轻松搞定!" target="_blank">· 联想笔记本一键重装Win10系统图文教程,小白也能...</a><span class="text-muted pull-right">02-05</span></dd> <dd><a href="/win11/1005319.html" title="笔记本重装系统图文教程:从光盘启动一步到位" target="_blank">· 笔记本重装系统图文教程:从光盘启动一步到位</a><span class="text-muted pull-right">02-05</span></dd> </dl> <dl class="col-sm-4 site-link"> <dt>好站推荐</dt><dd> <a href="https://www.runoob.com" title="菜鸟教程(www.runoob.com)提供了编程的基础技术教程, 介绍了HTML、CSS、Javascript、Python,Java,Ruby,C,PHP , MySQL等各种编程语言的基础知识。 同时本站中也提供了大量的在线实例,通过实例,您可以更好的学习编程。" target="_blank">菜鸟教程</a></dd><dd> <a href="https://www.jb51.cc" title="编程之家(www.jb51.cc)是成立于2017年面向全球中文开发者的技术内容分享平台。提供编程导航、编程问答、编程博文、编程百科、编程教程、编程工具、编程实例等开发者最需要的编程技术内容与开发工具支持,与你一起学习编程,相信编程改变未来!" target="_blank">编程之家</a></dd><dd> <a href="" title="前端之家 f2er.com 前端开发人员所需学习知识手册。" target="_blank">前端之家</a></dd></dl> <dl class="col-sm-2 site-link"> <dt>商务合作</dt> <dd><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=76874919&site=qq&menu=yes">联系我们</a></dd> </dl> </div> <div class="copyright"> Copyright © 2019 前端之家. 当前版本 V7.0.16<br> <span class="ml5">前端之家 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">闽ICP备13020303号-10</a></span> </div> </div> </footer> <script type="text/javascript" src="/js/base.js"></script> </body> </html>