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
继续阅读与本文标签相同的文章
人工智能简史(一)——萌芽
TOP 10:初学者需要掌握的10大机器学习算法
-
OpenSSL 1.1.1的裁剪
2026-05-19栏目: 教程
-
Springboot+mockito进行单元测试心得整体
2026-05-19栏目: 教程
-
如何用“云”读懂女生的心?TA 做到了
2026-05-19栏目: 教程
-
基于ASP.Net Core开发的一套通用后台框架
2026-05-19栏目: 教程
-
Spring Cloud开发人员如何解决服务冲突和实例乱窜?
2026-05-19栏目: 教程
