Expresss+gulp+MongoDB搭建网站(二)--创建一个工程

 创建一个目录,起名为website,这就是我们以后的工程目录。

一、创建package.json文件

 进入该目录,在命令行输入 npm init ,为工程创建一个package.json文件,命令要求输入一些参数,如工程名、版本号等,按回车接受默认设置。

$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (website) project
version: (1.0.0) 
description: 
git repository: 
keywords: 
license: (ISC) 
About to write to /Users/zhaoshanshan/work/website/package.json:

{
  "name": "project",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "zss",
  "license": "ISC",
  "devDependencies": {
    "express": "^4.16.2"
  },
  "dependencies": {},
  "description": ""
}


Is this ok? (yes) 


二、安装express并创建一个项目

 安装express,在命令行执行:


$ npm install express --save

由于express3+把创建app的功能分离出来为express-generator,因此需要再安装express-generator:


$ npm install express-generator --save

 (mac需要root用户安装,输入sudo -s,进入root用户即可)
 接下来输入(-e:指定使用 ejs 作为模板引擎):


express -e project

 然后进入project目录,输入npm install 安装项目依赖包。

这样就创建了一个名为project的项目,目录结构如下:

其中:

  • app.js:启动文件
  • package.json:存放项目信息及配置依赖
  • node_modules:存放项目依赖库
  • public:存放 imagejscss等文件
  • routes:存放路由文件
  • views:存放视图文件
  • bin:存放可执行文件

命令行输入:npm start,打开浏览器输入地址:http://localhost:3000/ ,可以看到 

 下一节,继续介绍gulp及webpack。








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值