维纳斯和阿多尼斯故事_认识阿多尼斯! 适用于node.js的laravel样式mvc框架-csdn博客


本站和网页 https://blog.csdn.net/culiu9261/article/details/107545105 的作者无关,不对其内容负责。快照谨为网络故障时之索引,不代表被搜索网站的即时页面。

维纳斯和阿多尼斯故事_认识阿多尼斯! 适用于Node.js的Laravel样式MVC框架-CSDN博客
维纳斯和阿多尼斯故事_认识阿多尼斯! 适用于Node.js的Laravel样式MVC框架
最新推荐文章于 2024-04-19 08:38:46 发布
culiu9261 阅读量429 收藏 点赞数 文章标签: 中间件 数据库 python java 编程语言 原文链接:
https://scotch.io/tutorials/meet-adonisjs-a-laravel-style-mvc-framework-for-node-js
版权
维纳斯和阿多尼斯故事
Node.js is one of the emerging technologies to write real-time applications using one of your favorite web languages:
Javascript
. With the ample choices of frameworks to write your first web server, not even a single one offers the desired developer experience. This is where AdonisJs shines.
Node.js是使用您最喜欢的Web语言之一
编写实时应用程序的新兴技术之一。 有了足够多的框架来编写您的第一个Web服务器,甚至没有一个可以提供所需的开发人员体验。 这就是AdonisJs闪耀的地方。
AdonisJs
is a beautifully crafted
MVC framework
for Node.js. In this article I'll show you how to get started with AdonisJs by installing the framework, discussing the features and creating a welcome page.
是一个精巧的Node.js
MVC框架
。 在本文中,我将向您展示如何通过安装框架,讨论功能并创建欢迎页面来开始使用AdonisJs。
什么是AdonisJs?
What is AdonisJs?
is inspired by a Php Framework called
Laravel
. It borrows the concepts of Dependency injection and service providers to write beautiful code which is testable to its core.
受到名为
的Php框架的
启发
。 它借用了依赖注入和服务提供者的概念来编写可对其核心进行测试的漂亮代码。
In the age of shiny web frameworks, AdonisJs focuses on the key aspects of creating stable and scalable web applications, some of them are:
在闪亮的Web框架时代,AdonisJs专注于创建稳定且可扩展的Web应用程序的关键方面,其中一些是:
开发者经验
Developer Experience
The framework makes use of latest inbuilt ES2015 features to get rid of spaghetti code. You will hardly find yourself writing
callbacks
since there is a solid support for ES2015 generators. Also, the OOP nature of the framework helps you in abstracting your code into multiple re-usable chunks.
该框架利用最新的内置ES2015功能来摆脱意大利面条式代码。 您几乎不会发现自己编写
回调,
因为对ES2015生成器提供了可靠的支持。 同样,框架的OOP性质可帮助您将代码抽象为多个可重用的块。
一致的API
Consistent API
The API throughout the code base is so consistent that after working for a while, you will be able to guess the method names, expected output, etc.
整个代码库中的API都是一致的,经过一段时间后,您将能够猜出方法名称,预期输出等。
速度与生产力
Speed & Productivity
AdonisJs ships with a bunch of 1st party components known as providers. Writing entire web server is a matter of weeks(if not days). It ships with solid support for
Mailing
Authentication
Redis
SQL ORM
Data validation and sanitization
, etc.
AdonisJs附带了许多称为提供程序的第一方组件。 编写整个Web服务器大约需要数周(如果不是几天的话)。 它附带了对
,
Data验证和清理
等的可靠支持。
安装AdonisJs
Installing AdonisJs
The installation process is straight forward. Just make sure you have got versions of
node >= 4.0
and
npm >=3.0
安装过程很简单。 只要确保您具有的
Let's start by installing
adonis-cli
globally using npm. It is a command line tool to scaffold new applications within a matter of seconds.
让我们从使用npm全局安装
开始。 它是一个命令行工具,可以在几秒钟内支持新的应用程序。
npm
i -g adonis-cli
Now we can start by creating new projects. For this article, we will setup a project called
hello-adonis
现在我们可以开始创建新项目。 对于本文,我们将设置一个名为
的项目。
adonis new hello-adonis
Above command will setup a new project with the pre-configured directory structure. Don't get overwhelmed by the directory structure as in next article we will talk about it.
上面的命令将使用预配置的目录结构设置一个新项目。 不要被目录结构淹没,因为在下一篇文章中我们将讨论它。
Now
cd
into the newly configured project and executing the following command to start the HTTP server.
现在,使用
进入新配置的项目,并执行以下命令来启动HTTP服务器。
start
# info adonis:framework +6ms serving app on localhost:3333
Open
http://localhost:3333
to see the welcome page.
打开
http:// localhost:3333
以查看欢迎页面。
In this article, we will discuss the framework concepts and some exciting features and in the next article, we will have fun by writing some code.
在本文中,我们将讨论框架概念和一些令人兴奋的功能,在下一篇文章中,我们将通过编写一些代码来获得乐趣。
强大的路由
Powerful Routing
AdonisJs has out of the box support for defining fluent routes. Setting up express style routes to CRUD resources is a just a matter of seconds.
AdonisJs具有开箱即用的支持,用于定义流畅的路线。 设置到CRUD资源的快速样式路由仅需几秒钟。
Let's explore the framework routing layer.
让我们探索框架路由层。
const
Route
=
use
'Route'
// importing route
get
'/home'
'HomeController.welcome'
Above we defined a simple route to URL
/home
. Once the given route is called the
welcome
method on HomeController will be invoked.
上面我们定义了一个简单的URL
路由。 调用给定的路由后,将调用HomeController上的
方法。
Let's move to my favorite part of routing called
resources
. Resources help you in defining multiple conventional RESTful routes within a single line of code.
让我们转到我最喜欢的路由部分,称为
。 资源可帮助您在一行代码中定义多个常规RESTful路由。
resource
'users'
'UserController'
Above line of code will set a total of seven routes.
上面的代码行将设置总共7条路线。
Url
Verb
Controller Method
Purpose
/users
GET
index
Show list of all users
/users/create
create
Display a form to create a new user.
POST
store
Save user submitted via form to the database.
/users/:id
show
Display user details using the id
/users/:id/edit
edit
Display the form to edit the user.
PUT/PATCH
update
Update details for a given user with id.
DELETE
destroy
Delete a given user with id.
网址
动词
控制器方式
目的
/用户
得到
指数
显示所有用户的列表
/用户/创建
创造
显示表单以创建新用户。
开机自检
商店
将通过表单提交的用户保存到数据库中。
/ users /:id
表演
使用ID显示用户详细信息
/ users /:id / edit
编辑
显示表单以编辑用户。
PUT / PATCH
更新
更新具有ID的给定用户的详细信息。
删除
破坏
删除具有ID的给定用户。
That's not all. You can also filter and extend resources based upon the nature of the application.
那不是全部。 您还可以根据应用程序的性质来过滤和扩展资源。
only
'index'
'store'
'update'
'destroy'
addMember
'profile'
Whoooo! As I said, the fluent method chaining makes it so simple to filter the resources down to only four routes, and also with the help of
, we can add a new route to the
users
resource.
!! 就像我说的那样,流利的方法链接使将资源过滤到仅四个路由变得如此简单,并且借助
,我们可以向
资源添加新的路由。
Here's a neat video to show off some more routing features:
这是一个简洁的视频,展示了更多的路由功能:
路由中间件
Route Middleware
Before we move onto the next feature, let's see how to work with route middleware.
在介绍下一个功能之前,让我们看一下如何使用路由中间件。
. get ( '/account' , 'UserController.account' )
. middleware ( 'auth' )
Middleware(s) are defined by chaining the
middleware
method, and you are free to specify one or more middleware by passing multiple arguments.
中间件是通过链接
方法定义的,您可以通过传递多个参数来自由指定一个或多个中间件。
活动记录ORM
Active Record ORM
If you ever worked with Rails or Laravel, you will feel right at home. AdonisJs ORM called
Lucid
is a robust implementation of Active Record. It supports all popular SQL databases like
MYSQL
Oracle
PostgreSQL
SQLite
, etc. Also, the database engine has support for data models, fluent query builder, and migrations.
如果您曾经与Rails或Laravel一起工作过,您会感到宾至如归。 AdonisJs称为
Lucid的
ORM是Active Record的可靠实现。 它支持所有流行SQL数据库,例如
等。此外,数据库引擎还支持数据模型,流畅的查询生成器和迁移。
Let's take a quick look at how to define and interact with SQL data models also known as
Lucid models
让我们快速看一下如何定义SQL数据模型并与之交互(也称为
Lucid模型)
const Lucid = use ( 'Lucid' )
class User extends Lucid {
posts ( ) {
return this . hasMany ( 'App/Model/Post' )
Now you can use the Post Model as follows.
现在,您可以按以下方式使用发布模型。
const User = use ( 'App/Model/User' ) // require user model
yield User . all ( ) // get all users
const loue = yield User . findBy ( 'username' , 'Loue' ) // find by username
yield loue . posts ( ) . fetch ( ) // fetch all posts by loue
Ace命令
Ace Commands
There's hardly any Node.js framework which gives you the power to write project-specific terminal commands with the ease as similar to AdonisJs. AdonisJs has a beautiful tool called
Ace
, which makes it super easy and intuitive to write your terminal commands. Don't believe me! Let's check it out.
几乎没有任何Node.js框架可以像AdonisJs一样轻松地编写特定于项目的终端命令。 AdonisJs有一个漂亮的工具叫做
,它使编写终端命令变得非常容易和直观。 不相信我! 让我们来看看。
Commands are stored in the
app/Commands
directory, and each file represents a single command. Let's play with the pre-existing
Greet
command.
命令存储在
目录中,每个文件代表一个命令。 让我们玩一下预先存在的
命令。
Run the following command from the root of your project.
从项目的根目录运行以下命令。
./ace greet "Your name."
It is the simplest command you can ever write, but that does not limit you from creating more useful commands. For now, we will discuss the basic structure of a command class. Whereas you must reference the
offical documentation
这是您可以编写的最简单的命令,但这并不限制您创建更多有用的命令。 现在,我们将讨论命令类的基本结构。 而您必须参考
官方文档
const Command = use ( 'Command' )
class Greet extends Command {
get signature ( ) {
return 'greet {name}'
get description ( ) {
return 'Greet a user with their name.'
* handle ( args , options ) {
// called when command is executed
Command
signature
defines the command name and the required/optional arguments to be passed when running the command.
命令
定义命令名称和运行命令时要传递的必需/可选参数。
The description gets displayed on the help screen.
说明显示在帮助屏幕上。
handle
is an ES2015 generator method, which is called when your command is invoked. You are free to do almost anything inside this method.
是ES2015生成器方法,在调用命令时会调用该方法。 您可以在此方法内执行几乎所有操作。
功能一览
Features At A Glance
There is a lot more to cover when it comes to AdonisJs features. Let's sum them within a small list to keep this first article simple and easy to digest.
关于AdonisJs的功能,还有很多要讲的内容。 让我们将它们汇总在一个小列表中,以使第一篇文章简单易懂。
Multi-transport mailer.
多路运输邮件。
Robust middleware layer to interact with incoming HTTP requests.
强大的中间件层可与传入的HTTP请求进行交互。
Nunjucks based templates.
基于Nunjucks的模板。
Support for emitting and listening to application-wide events.
支持发出和监听应用程序范围的事件。
Inbuilt support for Redis.
对Redis的内置支持。
Secure and straightforward file uploads.
安全,简单的文件上传。
Security features with support for
CORS
CSRF
Content sniffing
XSS
attacks.
支持
内容嗅探
攻击的安全功能。
Supportive and friendly community.
支持和友好的社区。
未来
Future
AdonisJs is under active development with the latest release of version
3.0
. Major API specs have finalized so that upcoming releases will have less or no breaking changes.
AdonisJs正在积极开发最新版本的
版。 主要的API规范已经完成,因此即将发布的版本将有很少或没有重大更改。
Also, there is a complete roadmap on
Trello
sharing what's next in the queue. To summarize, you will soon get support for:
另外,在
上有完整的路线图,共享队列中的下一步。 总而言之,您很快就会获得以下支持:
Social Authentication via Facebook, Google, Github, etc.
通过Facebook,Google,Github等进行的社交身份验证。
Complete testing framework.
完整的测试框架。
Support for caching database queries and views fragments.
支持缓存数据库查询和视图片段。
Inbuilt support for posting messages to Slack.
对将消息发布到Slack的内置支持。
接下来的是!
Coming up Next!
This post is an introduction to
, walking through some of the fundamentals and key features of the framework. In the upcoming post, we will together write a simple link sharing website like
EchoJs
这篇文章是对
的介绍,并介绍了该框架的一些基础知识和关键功能。 在即将发布的帖子中,我们将共同编写一个简单的链接共享网站,例如
翻译自:
优惠劵
关注
点赞
觉得还不错?
一键收藏
知道了
评论
维纳斯和阿多尼斯故事Node.js is one of the emerging technologies to write real-time applications using one of your favorite web languages: Javascript. With the ample choices of frameworks to write your first web...
复制链接
扫一扫
ado
nis命令new
蛐蛐的博客
12-12
336
new 命令位于@
nisjs
cli
/src/Commands/New目录下,其中step目录下包含了执行命令的各个步骤
/src/Commands/New/index.js:
//处理方法,获取选项当中的name属性,即项目名称
async handle ({ name }, options) {
//获取新建项目各个步骤
const steps
小学英语希腊神话双语小
故事
维纳斯
阿多
尼斯
阅读素材202003021305
09-09
参与评论
您还未登录,请先
登录
后发表或查看评论
分享10个NodeJS相关的专业级工具
前端达人
07-24
256
Node.js
已成为开发人员创建强大且可扩展的Web应用程序的首选选项。根据2022年StackOverflow开发者调查,
被评为专业开发人员中使用最广泛的Web
框架
。这个成功可以归功于其庞大的生态系统,其中提供了许多工具和
。了解并接纳这个生态系统对于优化性能和简化任何
应用程序的生产过程至关重要。在本文中,我们将探讨用于生产环境的顶级
工具和
,以帮助...
nis的LUCID ORM模块中save方法
liu1664691399的博客
01-06
206
例:
User.save(),当对象没有变化而保存时报错“对象没有变化”
Ado
nisJs
(Node
)学习总结
weixin_30433075的博客
05-18
491
先列出作为前端开发人员必须知道的10个NodeJs
一个服务端渲染的
MVC
,它是
(PHP
)的一个 NodeJS 版本。
可以安装脚手架工具
nis-
,用于创建
nis项目。
npm i -g @
nis new test-
nis
cd test-
nis s...
使用
nisJS
构建Web应用
culiu9261的博客
07-23
861
is a
framework. It offers a stable eco-system to write web servers so that you can focus on business needs over finalizing which package to choose or not. In this tutorial, I’ll b...
test_api_
:测试用于创建API的
03-19
应用这个项目是基本的API REQUEST和consul API with react技术领域
(JS)实战后退码头工人启动Docker撰写项目cd box && docker-compose up停止Docker撰写项目cd box && docker-compose down
simple_
nis_api:只是一个简单的
API
02-22
nis API应用程序 这是在
中创建API服务器的样板,它已预先配置。
人体分析仪 验证 CORS
清醒的ORM
迁移与种子 设置 使用
nis命令安装蓝图
nis new yardstick --api-only
或手动克隆存储库,然后...
02-21
nis API应用程序这是在
中创建API服务器的样板,它已预先配置。 人体分析仪验证CORS 清醒的ORM 迁移与种子设置使用
nis new yardstick --api-only 或手动克隆存储库,然后运行npm ...
vue-
nis-todo:使用
和vue的待办事项清单
02-13
lucid-mongo:Mongodb ODM for
05-02
清醒的蒙哥
lucid-mongo是mongo查询生成器和ORM。 它还支持
迁移,种子和工厂,如@
nis / lucid。
:folded_hands: 该存储库基于@
nis / lucid,仅与mongodb一起使用。
特征?
除了只是查询构建器之外,lucid-mongo还具有以下功能。
基于ES6类的数据模型。
模型钩
社团协会
序列化器(Vanilla和JSON API)
移居
工厂和种子
Lucid-mongo 2.0版现在可以独立使用,也可以与
一起使用。您可以在上详细了解
及其所有功能。
:evergreen_tree:
您可以在此处看到
的示例
节点/操作系统目标
该仓库/分支应该可以在所有主要的OS平台上正常运行,并以
>=8.0目标
安装
一起使用
nis命令安装npm。
nis insta
Ubuntu 10.04
(Lucid ) 更新源
weixin_30407099的博客
07-11
563
deb http://ubuntu.srt.cn/ubuntu/ lucid main restricted universe multiversedeb http://ubuntu.srt.cn/ubuntu/ lucid-security main restricted universe multiversedeb http://ubuntu.srt.cn/ubuntu/ lu...
Venus
weixin_34228387的博客
06-28
1811
http://wiki.hexnova.com/display/Venus/HOME
它是由(Venus service framework)+服务路由产品(Venus-Bus)+服务注册中心(Venus-Registry) 组合而成,提供远程服务。它着开发简单、高性能、高并发能力的服务端
Venus Service Framework提供服务器端开发SDK以及客户端SDK。它们之间采用...
古希腊神话
纸质妖怪的小博
08-11
2614
阿芙罗狄蒂爱
胜过爱别的任
何人,因为他是一个精神抖擞、生气勃勃的少年猎手。她离开了奥林波斯山的住
所来到林中。她装扮成一个女猎手,让这个年轻人整日陪伴左右,并与他一起游
遍了山林、河谷。她跟着猎狗,欢呼雀跃,追赶着无害的动物。他们一起渡过了
一段美好时光。虽然她奉劝了他许多次不要捕杀像狮子和狼这样的野兽,但年轻
人只是嘲笑她的想法。有一天,当她如此奉劝他之后,她坐
Middleware【
】简介
Defonds 的专栏
06-22
4654
是一种计算机软件连接了软件部件或者应用程序。 这种软件有一组服务构成,这些服务包括允许多进程运行在一个或者多个机器上以达到在网络中互相交互的目的。
nodejs后端
star排名(截止202007)
大黄蜂的博客
08-03
2521
第一名: express 49.4k (2010年1月发布) 目前star 和下载量最高的老牌
https://github.com/expressjs/express
第二名: koa 29.6k (2013年11月发布) express 的继任者。
https://github.com/koajs/koa
第三名: nest.js 28.8k (2017年11月发布) 目前上榜
中发布最晚,也是star 最高且增长最快的 typescript 后端
https://github.c
预渲染vue.js应用程序(使用node或
laravel
qq_43067585的博客
07-28
488
服务器端渲染现在非常流行。但它也并非没有缺点。预渲染是一种替代方法,在某些情况下甚至可能更好。下面我们来看一下如何预渲染vue.js应用程序。
在本文中,我们将探讨预渲染如何与vue.js一起工作,并看两个示例:一个是
node.js
项目,一个是
项目。
一、服务端渲染
基于
script的应用程序的一个缺点是,浏览器从服务器接收到的页面基本上是空的。在下载并运行
Java
script之前,无法构建DOM。
这意味着用户必须等待更长的时间才能看到任何东西。如果爬虫程序不能快速查看页
消息
主备方案选型实践
Venus专栏
04-20
1136
背景介绍
该消息
由三个子系统组成:客户端SDK、Server和控制管理中心(Admin)。我们所说的主备主要是针对Server,而Server的节点是局部有状态的,具体而言就是发布无状态,但是拉取有状态。因此,对于发布而言,由于分布式部署所以本身具备高可用性;但是对于拉取,就存在单点的可用性问题。
主备切换的关键问题
实现主备切换,需要解决两个核心问题:
1. 解决主备之间状态检
Venus: 简单、高性能、高并发
开源remoting
dy_f的专栏
03-15
1007
http://www.iteye.com/topic/1118484
 
Venus 是一个简单的、高性能、高并发能力的
开源Remoting
 wiki地址:http://wiki.hexnova.com/display/Venus/HOME
性能测试:http://wiki.hexnova.com/p...
Ruby中Rack
的使用场景和注意事项
最新发布
weixin_43784341的博客
04-19
589
Rack
在Ruby中是一种非常常见的模式,用于处理HTTP请求和响应。它们位于Web服务器和Web应用之间,允许开发者在请求到达应用之前或响应返回给客户端之后执行某些操作。Rack
可以执行诸如日志记录、身份验证、错误处理、缓存等任务。
“相关推荐”对你有帮助么?
非常没帮助
没帮助
一般
有帮助
非常有帮助
提交
CSDN认证博客专家
CSDN认证企业博客
码龄8年
暂无认证
原创
周排名
180万+
总排名
56万+
访问
等级
1110
积分
33
粉丝
52
获赞
307
私信
热门文章
remove git_如何使用“ git Remove”而不删除文件
11349
在Visual Studio Code中使用漂亮的代码格式化
10775
react 实现滚动加载_在React中实现平滑滚动
10377
电子墨水标签_使用墨水构建响应电子邮件模板
7011
flask身份验证_使用Flask登录进行身份验证和授权
6151
您愿意向朋友推荐“博客详情页”吗?
强烈不推荐
不推荐
一般般
推荐
强烈推荐
最新文章
开源api_开源IP地理位置API
nodejs pm2 迁移_从NodeJS迁移到Go
css网格_深入研究CSS网格
2020年
767篇
目录
被折叠的 
 条评论
为什么被折叠?
到【灌水乐园】发言
查看更多评论
添加红包
祝福语
请填写红包祝福语或标题
红包数量
红包个数最小为10个
红包总金额
红包金额最低5元
余额支付
当前余额
3.43
前往充值 >
需支付:
10.00
取消
确定
下一步
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝
规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额
抵扣说明:
1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。
余额充值