安装nodejs环境
官网下载地址:https://nodejs.org/en/download/;
新建Adonisjs项目
打开命令行窗口(这里以windows为例介绍),在命令行窗口中输入以下命令:
D:\workspace\nodejs>npm init adonis-ts-app@latest pj_hell
npx: installed 193 in 10.965s
_ _ _ _
/ \ __| | ___ _ __ (_)___ | |___
/ _ \ / _` |/ _ \| '_ \| / __|_ | / __|
/ ___ \ (_| | (_) | | | | \__ \ |_| \__ \
/_/ \_\__,_|\___/|_| |_|_|___/\___/|___/
CUSTOMIZE PROJECT
> Select the project structure ... Press <ENTER> to select
api (Tailored for creating a REST API server)
>web (Traditional web application with server rendered templates)
slim (A smallest possible AdonisJS application)
系统提示三个选项,api,web,slim,这里我们选择 web, 然后继续安装,安装完成界面如下
> Select the project structure · web
> Enter the project name · pj_hell
> Setup eslint? (y/N) · false
> Configure webpack encore for compiling frontend assets? (y/N) · false
RUNNING TASKS
> Scaffold project 77 ms
> Install dependencies 29 s
> Configure installed packages 850 ms
[ success ] Project created successfully
╭─────────────────────────────────────────────────╮
│ Run following commands to get started │
│─────────────────────────────────────────────────│
│ │
│ > cd pj_hell │
│ > node ace serve --watch │
│ │
╰─────────────────────────────────────────────────╯
D:\workspace\nodejs>
接下来我们用vscode打开项目查看目录结构
接下来我们运行项目看一下,命令行或vscode的终端中输入命令:node ace serve --watch
出现以下界面,说明项目运行起来了;
PS D:\workspace\nodejs\pj_hell> node ace serve --watch
[ info ] building project...
[ info ] starting http server...
[1623337134401] INFO (pj_hell/14596 on DESKTOP-NS66ME0): started server on 0.0.0.0:3333
[ info ] watching file system for changes
╭─────────────────────────────────────────────────╮
│ │
│ Server address: http://127.0.0.1:3333 │
│ Watching filesystem for changes: YES │
│ │
╰─────────────────────────────────────────────────╯
在浏览器中输入 http://127.0.0.1:3333查看运行结果