使用 Express 创建Node服务 入门

使用 Express 创建Node服务 入门



前言

使用Express框架快速搭建Web应用程序


一、依赖环境

需要 Node 环境

二、安装express依赖包

/*全局安装*/
npm install -g express
npm install -g express-generator

三、搭建步骤

/* 1. 创建项目,本文项目使用 ejs html模板, css加入了less解析中间件 ,-e --css less 可以按需添加 */
express -e --css less projectName 

/* 2. 进入项目 */
cd projectName

/* 3. 安装模块依赖 */
npm install

/* 4. 启动项目 */
npm run start

/* 5.浏览器输入网址 http://127.0.0.1:3000  下图表示运行成功!*/

在这里插入图片描述


四、express 指令扩展

/* express 帮助命令查看所有支持命令 */
express -h
/* 显示结果 */

  Usage: express [options] [dir]

  Options:

        --version        output the version number
    -e, --ejs            add ejs engine support
        --pug            add pug engine support
        --hbs            add handlebars engine support
    -H, --hogan          add hogan.js engine support
    -v, --view <engine>  add view <engine> support (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
        --no-view        use static html instead of view engine
    -c, --css <engine>   add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git            add .gitignore
    -f, --force          force on non-empty directory
    -h, --help           output usage information

指令说明:

/*  -e, --ejs  (添加 ejs模板引擎)  代表两种写法 效果相同 */
express -e projectName
/*  或 */
express --ejs projectName
/*  -c, --css <engine>  (表示添加样式文件中间) 代表两种写法 */
express -c projectName
或
express --css sass projectName
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DBAA_ws

聪明的人 都点赞关注加收藏了!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值