NodeJs 项目基础架构搭建分析

熊孩纸 阅读:274 2021-03-31 20:59:56 评论:0

第一步:创建项目存储路径(C:\node_workspace),创建NodeJs 项目(mongodb_desk) 并初始化

C:\>mkdir node_workspace 
 
C:\>cd node_workspace 
 
C:\node_workspace>mkdir mongodb_desk 
 
C:\node_workspace>cd mongodb_desk 
 
C:\node_workspace\mongodb_desk>cnpm 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: (mongodb_desk) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to C:\node_workspace\mongodb_desk\package.json: 
 
{ 
  "name": "mongodb_desk", 
  "version": "1.0.0", 
  "description": "", 
  "main": "index.js", 
  "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
  }, 
  "author": "", 
  "license": "ISC" 
} 
 
 
Is this OK? (yes) yes

第二步:mongodb_desk 项目目录结构:

建立三个文件夹:public、routes、views

mongodb_desk 项目目录结构:

对应文件及其文件夹说明:
models 存放操作数据库的文件

public 存放静态文件,如 css、图片等

routes 存放路由文件

views 存放模板文件

app.js 程序主文件

package.json 存储项目的信息,比如项目名、描述、作者、依赖等

至此一个nodejs 项目的基础框架搭建完毕。

声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

发表评论
搜索
KIKK导航

KIKK导航

排行榜
关注我们

一个IT知识分享的公众号