本文作者:问几许

Nodejs 的 Express 安装及项目创建

问几许 6年前 ( 2018-03-29 ) 2043 抢沙发
Nodejs 的 Express 安装及项目创建摘要: 安装首先保证自己已经安装过Node,才能安装Express。安装Expressnpm install express -g安装Express生成器np...

安装

首先保证自己已经安装过Node,才能安装Express。

安装Express

npm install express -g

安装Express生成器

npm install express-generator -g

#检测是否安装正确
PS C:\WINDOWS\system32> 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

创建项目

#一般安装ejs模板
express -e myfirstexpress
#安装模块
npm install body-parser --save
npm install cookie-parser --save
npm install multer --save

body-parser : node.js 中间件,用于处理 JSON, Raw, Text 和 URL 编码的数据。

cookie-parser : 这就是一个解析Cookie的工具。通过req.cookies可以取到传过来的cookie,并把它们转成对象。

multer : node.js 中间件,用于处理 enctype="multipart/form-data"(设置表单的MIME编码)的表单数据。

运行项目

cd myfirstexpress
npm start

> myfirstexpress@0.0.1 start /root/myfirstexpress  
> node ./bin/www

访问项目

然后在自己的浏览器中输入 :http://localhost:3000


文章版权及转载声明

作者:问几许本文地址:https://wenjixu.com/blog/28.html发布于 6年前 ( 2018-03-29 )
文章转载或复制请以超链接形式并注明出处问几许

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

阅读
分享

发表评论

快捷回复:

评论列表 (暂无评论,2043人围观)参与讨论

还没有评论,来说两句吧...