thinkjs 创建项目之helloworld
thinkjs 创建项目之helloworld
使用node.js开发应用程序,光有node.js不足以满足业务需求,而且太原始了,需要选择一些优秀的框架加速开发和提高质量。站在巨人肩膀上,尿的更高些。
之前了解express和koa,偶然看到sails.js太厉害了,跟socket.io结合一起,自动创建数据库,网上有个教程一分钟搞定sails.js demo,orm是waterline,几乎搞定各种数据库,而且还能同时配置访问多个不同类型数据库。集成能力太强了。当时thinkjs也看了下,还是1.0阶段,感觉不是成熟,thinkjs发了2.0才真正关注,结合中国国情的很多问题,确定选择thinkjs。比如你想找sails的人解答问题比较困难,thinkjs的qq群回复很快直接和团队沟通。
ThinkJS 是一款使用 ES6/7 特性全新开发的 Node.js MVC 框架,使用 ES7 中async/await,或者 ES6 中的 */yield 特性彻底解决了 Node.js 中异步嵌套的问题。同时吸收了国内外众多框架的设计理念和思想,让开发 Node.js 项目更加简单、高效。
1、安装thinkjs
npm install -g thinkjs@2
//查看版本号
thinkjs -v
环境搭建完了,官方做双周升级,目前最新版本是2.1.7,记得命令行要带上@2;
2、创建helloworld应用程序
我们生成个万能的helloworld,强烈推荐采用es6/7的方式编程。带--es就是生成支持es6/7。
thinkjs new helloworld --es
create : helloworld
create : helloworld\package.json
create : helloworld\.thinkjsrc
create : helloworld\nginx.conf
create : helloworld\pm2.json
create : helloworld\.gitignore
create : helloworld\README.md
create : helloworld\www
create : helloworld\www\development.js
create : helloworld\www\production.js
create : helloworld\www\testing.js
create : helloworld\www\README.md
create : helloworld\www\static
create : helloworld\www\static\js
create : helloworld\www\static\css
create : helloworld\www\static\img
create : helloworld\src
create : helloworld\src\common\bootstrap
create : helloworld\src\common\bootstrap\middleware.js
create : helloworld\src\common\bootstrap\global.js
create : helloworld\src\common\config
create : helloworld\src\common\config\config.js
create : helloworld\src\common\config\view.js
create : helloworld\src\common\config\db.js
create : helloworld\src\common\config\hook.js
create : helloworld\src\common\config\session.js
create : helloworld\src\common\config\error.js
create : helloworld\src\common\config\env
create : helloworld\src\common\config\env\development.js
create : helloworld\src\common\config\env\testing.js
create : helloworld\src\common\config\env\production.js
create : helloworld\src\common\config\locale
create : helloworld\src\common\config\locale\en.js
create : helloworld\src\common\controller
create : helloworld\src\common\controller\error.js
create : helloworld\view\common
create : helloworld\view\common\error_400.html
create : helloworld\view\common\error_403.html
create : helloworld\view\common\error_404.html
create : helloworld\view\common\error_500.html
create : helloworld\view\common\error_503.html
create : helloworld\src\home\config
create : helloworld\src\home\config\config.js
create : helloworld\src\home\controller
create : helloworld\src\home\controller\base.js
create : helloworld\src\home\controller\watermark.js
create : helloworld\src\home\logic
create : helloworld\src\home\logic\watermark.js
create : helloworld\src\home\model
create : helloworld\src\home\model\watermark.js
create : helloworld\view\home
create : helloworld\view\home\index_index.html
3、安装nodejs依赖包
//进入目录
$ cd helloworld
//安装依赖
$ npm install
按照提示先npm install依赖库,运行前就准备完成了。
最后编译并执行应用程序
npm run compile
npm run start
如此项目初始化就完成了,运行结果如图
因thinkjs2.0是用es6/es7编写,需要编译成es5执行,thinkjs会自动完成这一步,用任何开发工具改了文件,即刻编译看到结果。
4、helloworld展示
找到home/controller/index.js下index.js,给title赋值。
'use strict';
import Base from './base.js';
export default class extends Base {
/**
* index action
* @return {Promise} []
*/
indexAction(){
//auto render template file index_index.html
this.assign("title", "ThinkJS 官网");
return this.display();
}
}
我们再看看前端view/home/index_index.html,把controller里assign的title值打印出来。js模板引擎默认是ejs。
<header>
<div class="wrap">
<h1>A New App Created By ThinkJS <%= title%> </h1>
</div>
</header>
刷新浏览器就能看到。
如此,最简单的helloworld项目基本就完成了。
如若转载,请注明出处:sau交流学习社区-power by saucxs(程新松)(/page/206.html)
标签云
图文推荐
“深度学习”这十年:52篇大神级论文再现AI荣与光,12岁上大学、31岁成最年轻IEEE Fellow,前百度总裁张亚勤加盟清华,全球女性福音!DeepHealth深度学习模型检测乳腺癌完胜5名放射科医师,读博无门,就业碰壁,孤独当了7个月“民科”后,我的论文中了顶会Spotlight
saucxs 2020-01-03 10:04:09
1200 万部手机、500 亿实时位置数据,上帝视角还原特朗普全天行踪,自动驾驶玩漂移 斯坦福最新研究:《头文字D》无人车版来了,印度裔又要统领美国科学界?特朗普提名他领导美国国家科学基金会,GitHub排名第一!免费最强“抢票神器”在手,程序员抢票再不用跪求加速包
saucxs 2019-12-25 10:08:05
蝉联AI专业全球冠军!清华力压CMU再夺CSRankings高校AI排行王座,波士顿动力CEO:不排斥军方订单,就想你粗暴地对待机器狗,亚马逊Alexa突然发疯,读着论文教主人自杀:你活着地球人口会过剩,图神经网络的ImageNet?斯坦福大学等开源百万量级OGB基准测试数据集
saucxs 2019-12-24 09:57:45
2020 AAAI Fellow名单出炉!深度学习先驱Bengio和LeCun双双入选,李世石最后一战不敌AI“韩豆”!唯一战胜过AlphaGo的男人正式退役,GAN和PS合体会怎样?东京大学图像增强新研究:无需配对图像,增强效果还可解释,2019年最受关注的100项研究,AI“复活”蒙娜丽莎排第一
saucxs 2019-12-23 09:58:10
这家AI公司用面具破解中国人脸识别系统!微信、支付宝、火车站无一幸免,OpenAI公开Dota 2论文:胜率99.4%,「手术」工具连续迁移训练,9岁神童大学毕业前突然退学,转赴美国攻读电气工程博士,Reddit热议:15岁高中生用神经网络建立生命进化“新宇宙”
saucxs 2019-12-17 09:45:30
- 东方财富
- saucxs博客园
- weekly周报
- loveBook
- 前端博客
- 技术交流学习社区
- saucxs
- segmentfault
- saucxs的博客
- haorooms
- luckyscript
- 东方财富期货
- 峰云就她了
- binlive
- songEagle
- 且听风吟
- (TX)Heying Ye
- CG Online Judge
- Chris's Blog
- vueRouter
- 龙恩0707
- 鑫空间,鑫生活
- 木易杨
- MDN-js
- Cherry's Blog
- InterviewMap
- 安安哥的小戏台
- xiaojun1994-cat
- JavaScript-Garden
- junruchen-daily
- 秋天爱美丽
- web-summary-daily
- w3cplus-tb
- 潜行者m
- 于江水
- KieSun-git
- cnodejs
- aerminBlog
- fex_bd
- gwuhaolin-git
- Deboy's Blog
- react-china
- react.docschina
- Vuejs社区
- vuejsDoc
- cdnSocketIo
- shuaihuaCC
- colorize
- stazhu
- 前端学习
- IBM Dev社区
- linux运维笔记
- webpackDoc
- sayskyGithub
- 前端里
- 996.ICU
- electronjs
- CS-Notes
- mqyqingfengBlog
- beego官方
- 编码规范
- 阮一峰个人网站
- sessionstack
- damonareGoUp
- 咀嚼之味
- fe-interview
- xd-tayde/blog
- css-tricks
- ghmagical个人中心
- markyunp6
- hellogithub
- 霜序廿
- rin部落
- 建站素材
- 前端资源网
- CSS开发手册
- web技术交流
- 程新松个人网站
- wangEditor
- 小松博客
- 交流学习社区