一、安装配置Nodejs环境,已经使用express搭建web框架

参考:https://blog.csdn.net/qq_38209578/article/details/82593591
参考:https://www.cnblogs.com/learnings/p/7372718.html


一、查看npm的版本


输入:cnpm -v和输入npm -v
 

C:\Users\shenzhu>cnpm -v
'cnpm' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

C:\Users\shenzhu>npm -v
3.8.9

 

二、使用npm install express -g命令来安装express插件

输入:npm install express -g

C:\Users\shenzhu>npm install express -g
C:\Users\shenzhu\AppData\Roaming\npm
`-- express@4.16.4
  +-- accepts@1.3.5
  | +-- mime-types@2.1.21
  | | `-- mime-db@1.37.0
  | `-- negotiator@0.6.1
  +-- array-flatten@1.1.1
  +-- body-parser@1.18.3
  | +-- bytes@3.0.0
  | +-- http-errors@1.6.3
  | | `-- inherits@2.0.3
  | +-- iconv-lite@0.4.23
  | | `-- safer-buffer@2.1.2
  | `-- raw-body@2.3.3
  +-- content-disposition@0.5.2
  +-- content-type@1.0.4
  +-- cookie@0.3.1
  +-- cookie-signature@1.0.6
  +-- debug@2.6.9
  | `-- ms@2.0.0
  +-- depd@1.1.2
  +-- encodeurl@1.0.2
  +-- escape-html@1.0.3
  +-- etag@1.8.1
  +-- finalhandler@1.1.1
  | `-- unpipe@1.0.0
  +-- fresh@0.5.2
  +-- merge-descriptors@1.0.1
  +-- methods@1.1.2
  +-- on-finished@2.3.0
  | `-- ee-first@1.1.1
  +-- parseurl@1.3.2
  +-- path-to-regexp@0.1.7
  +-- proxy-addr@2.0.4
  | +-- forwarded@0.1.2
  | `-- ipaddr.js@1.8.0
  +-- qs@6.5.2
  +-- range-parser@1.2.0
  +-- safe-buffer@5.1.2
  +-- send@0.16.2
  | +-- destroy@1.0.4
  | `-- mime@1.4.1
  +-- serve-static@1.13.2
  +-- setprototypeof@1.1.0
  +-- statuses@1.4.0
  +-- type-is@1.6.16
  | `-- media-typer@0.3.0
  +-- utils-merge@1.0.1
  `-- vary@1.1.2


三、使用express新建项目
 

输入:express myapp

注:myapp是项目名称可以自己换,若是还没有安装express命令会提示如下:

C:\Users\shenzhu>express myapp
'express' 不是内部或外部命令,也不是可运行的程序
或批处理文件。

1、安装命令插件

输入:npm install -g express-generator

C:\Users\shenzhu>npm install -g express-generator
C:\Users\shenzhu\AppData\Roaming\npm\express -> C:\Users\shenzhu\AppData\Roaming\npm\node_modules\express-generator\bin\express-cli.js
C:\Users\shenzhu\AppData\Roaming\npm
`-- express-generator@4.16.0
  +-- commander@2.13.0
  +-- ejs@2.5.7
  +-- minimatch@3.0.4
  | `-- brace-expansion@1.1.11
  |   +-- balanced-match@1.0.0
  |   `-- concat-map@0.0.1
  +-- mkdirp@0.5.1
  | `-- minimist@0.0.8
  `-- sorted-object@2.0.1


 
 
 2、新建myAPP项目

 

安装完命令之后,重新输入:express myapp,就可以新建项目


 C:\Users\shenzhu>express myapp

  warning: the default view engine will not be jade in future releases
  warning: use `--view=jade' or `--help' for additional options


   create : myapp\
   create : myapp\public\
   create : myapp\public\javascripts\
   create : myapp\public\images\
   create : myapp\public\stylesheets\
   create : myapp\public\stylesheets\style.css
   create : myapp\routes\
   create : myapp\routes\index.js
   create : myapp\routes\users.js
   create : myapp\views\
   create : myapp\views\error.jade
   create : myapp\views\index.jade
   create : myapp\views\layout.jade
   create : myapp\app.js
   create : myapp\package.json
   create : myapp\bin\
   create : myapp\bin\www

   change directory:
     > cd myapp

   install dependencies:
     > npm install

   run the app:
     > SET DEBUG=myapp:* & npm start

 

四、新建好的项目的目录 

注意:建好的项目会保存在什么地方呢?

如上面的myapp项目,是在C:\Users\shenzhu这种目录下,所以最好是新建好自己的项目目录,然后进入到自己的项目目录下,再执行express的相关命令,这样项目工程就会创建在你自己建的目录下了

 

五、安装依赖模块

输入:app>npm install

C:\Users\shenzhu\NodeJSProject\app>npm install
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version of pug instead of ja
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
npm WARN deprecated constantinople@3.0.2: Please update to at least constantinople 3.1.1
app@0.0.0 C:\Users\shenzhu\NodeJSProject\app
+-- cookie-parser@1.4.3
| +-- cookie@0.3.1
| `-- cookie-signature@1.0.6
+-- debug@2.6.9
| `-- ms@2.0.0
+-- express@4.16.4
| +-- accepts@1.3.5
| | +-- mime-types@2.1.21
| | | `-- mime-db@1.37.0
| | `-- negotiator@0.6.1
| +-- array-flatten@1.1.1
| +-- body-parser@1.18.3
| | +-- bytes@3.0.0
| | +-- iconv-lite@0.4.23
| | | `-- safer-buffer@2.1.2
| | `-- raw-body@2.3.3
| +-- content-disposition@0.5.2
| +-- content-type@1.0.4
| +-- depd@1.1.2
| +-- encodeurl@1.0.2
| +-- escape-html@1.0.3
| +-- etag@1.8.1
| +-- finalhandler@1.1.1
| | `-- unpipe@1.0.0
| +-- fresh@0.5.2
| +-- merge-descriptors@1.0.1
| +-- methods@1.1.2
| +-- on-finished@2.3.0
| | `-- ee-first@1.1.1
| +-- parseurl@1.3.2
| +-- path-to-regexp@0.1.7
| +-- proxy-addr@2.0.4
| | +-- forwarded@0.1.2
| | `-- ipaddr.js@1.8.0
| +-- qs@6.5.2
| +-- range-parser@1.2.0
| +-- safe-buffer@5.1.2
| +-- send@0.16.2
| | +-- destroy@1.0.4
| | `-- mime@1.4.1
| +-- serve-static@1.13.2
| +-- setprototypeof@1.1.0
| +-- statuses@1.4.0
| +-- type-is@1.6.16
| | `-- media-typer@0.3.0
| +-- utils-merge@1.0.1
| `-- vary@1.1.2
+-- http-errors@1.6.3
| `-- inherits@2.0.3
+-- jade@1.11.0
| +-- character-parser@1.2.1
| +-- clean-css@3.4.28
| | +-- commander@2.8.1
| | | `-- graceful-readlink@1.0.1
| | `-- source-map@0.4.4
| |   `-- amdefine@1.0.1
| +-- commander@2.6.0
| +-- constantinople@3.0.2
| | `-- acorn@2.7.0
| +-- jstransformer@0.0.2
| | +-- is-promise@2.1.0
| | `-- promise@6.1.0
| |   `-- asap@1.0.0
| +-- mkdirp@0.5.1
| | `-- minimist@0.0.8
| +-- transformers@2.1.0
| | +-- css@1.0.8
| | | +-- css-parse@1.0.4
| | | `-- css-stringify@1.0.5
| | +-- promise@2.0.0
| | | `-- is-promise@1.0.1
| | `-- uglify-js@2.2.5
| |   +-- optimist@0.3.7
| |   | `-- wordwrap@0.0.3
| |   `-- source-map@0.1.43
| +-- uglify-js@2.8.29
| | +-- source-map@0.5.7
| | +-- uglify-to-browserify@1.0.2
| | `-- yargs@3.10.0
| |   +-- camelcase@1.2.1
| |   +-- cliui@2.1.0
| |   | +-- center-align@0.1.3
| |   | | +-- align-text@0.1.4
| |   | | | +-- kind-of@3.2.2
| |   | | | | `-- is-buffer@1.1.6
| |   | | | +-- longest@1.0.1
| |   | | | `-- repeat-string@1.6.1
| |   | | `-- lazy-cache@1.0.4
| |   | +-- right-align@0.1.3
| |   | `-- wordwrap@0.0.2
| |   +-- decamelize@1.2.0
| |   `-- window-size@0.1.0
| +-- void-elements@2.0.1
| `-- with@4.0.3
|   +-- acorn@1.2.2
|   `-- acorn-globals@1.0.9
`-- morgan@1.9.1
  +-- basic-auth@2.0.1
  `-- on-headers@1.0.1


六、使用npm start 运行项目

 

输入:npm start


1、刚开始报了下面的的错误

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.2.0
npm ERR! npm  v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! app@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\shenzhu\NodeJSProject\app\npm-debug.log

C:\Users\shenzhu\NodeJSProject\app>


从上面的提示看,说可能是npm或者nodejs不是最新版,但是我的npm是最新版的,所以我就重新
安装了一下nodejs,到官网里面又下载了一个最新的版本的nodejs,重新安装完成之后,就OK了,如下:

C:\Users\shenzhu\NodeJSProject\app>npm start

> app@0.0.0 start C:\Users\shenzhu\NodeJSProject\app
> node ./bin/www

七、node express新建的项目没有.idea


这个如果使用ide的话就有
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值