1.创建一个安装目录
$ mkdir myapp
$ cd myapp

2.使用npm创建一个安装包文件为你的应用
Use the npm init command to create a package.json file for your application.
$ npm init
3.下面这个命令设置一些东西比如名字,版本你可以敲回车接受大多数默认的,除了下面这个可以选择更改
This command prompts you for a number of things, such as the name and version of your application.For now, you can simply hit RETURN to accept the defaults for most of them, with the following exception:
**entry point: (index.js)*可以选择更改入口函数的名字类似main函数
Enter app.js, or whatever you want the name of the main file to be. If you want it to be index.js, hit RETURN to accept the suggested default file name.
敲下app.js或者任何你所想要的名字或者接受默认
4.现在安装express在myapp目录下,并将其保存在依赖list中
Now install Express in the myapp directory and save it in the dependencies list. For example
$ npm install express --save
To install Express temporarily and not add it to the dependencies list:(暂时安装express并且不把他装在依赖表里)
$ npm install express --no-save5
5.使用软件生成工具快速创建一个应用骨架
Use the application generator tool, express-generator, to quickly create an application skeleton.
使用express包安装这个命令行工具
The express-generator package installs the express command-line tool. Use the following command to do so:
$ npm install express-generator -g
6.查看是否安装成功
Display the command options with the -h option:
$ express -h
若出现找不到可利用软连接到/usr/local/bin下这样就可以全局搜索
sudo ln -s /usr/local/node-v10.14.1-linux-x64/bin/express /usr/local/bin
7.创建或者将路径转到myapp下
express --view=pug myapp
(文件都是pug类型的pug是一种类似于html的网页类型)
Then install dependencies(安装依赖)
$ cd myapp
$ npm install

On MacOS or Linux, run the app with this command:
$ DEBUG=myapp: npm start

运行这个app
8.打开浏览器127.0.0.1:3000访问express

​​​​​​

收藏 打印