Giter VIP home page Giter VIP logo

nxylene's Introduction

nodejs例子

练习nodejs大法,使用nodejs+mongodb+express4.x做个小实例。

安装依赖 & 启动

使用 grunt 管理项目,自动运行启动node.js 服务,监听js文件自动重启服务。监听静态文件css,js自动压缩合并静态文件。

  1. 使用前确保你已经安装了nodejs或者iojs了
  2. 使用前还确保你已经安装了mongodb了
  3. 启动mongodb
  4. npm install安装node包依赖
  5. 运行bower install安装项目前端框架(未来会使用),npm install -g bower安装bower
  6. npm install安装node包依赖
  7. 直接grunt就可以运行了,会自动启动node.js服务
#由于Gruntfile.js使用的是coffeescript所以全局安装
$ sudo npm install -g coffee-script

# 1.启动mongodb数据库
$ mongod --config /usr/local/etc/mongod.conf

# 2.mongod 是 MongoDB 系统的主要后台进程。它处理数据请求,管理数据访问,执行后台管理操作。
$ sudo mongod

# 进入在根目录安装依赖
$ bower install
$ npm install
#启动node.js服务和管理静态资源
$ grunt   
#启动node.js服务【带日志中间件和mongoose日志】和管理静态资源  
$ NODE_ENV=dev grunt   

# 预览
# 进入管理平台:http://127.0.0.1:8181/admin

文件夹结构说明

  • app/
    • controllers/ 文件夹负责业务逻辑处理
    • schemas/ 文件夹负责存放数据模式
    • models/ 文件夹负责存放数据结构模型
  • conf/ 文件夹负责路由订制,等配置文件
  • lib/ 存放工具模块
  • doc/ 学习文档
  • themes
    • default/默认皮肤
      • source/ 前端静态资源文件存放目录
      • views/ 存在静态模版文件

相关依赖

依赖说明

  • ejs:模板引擎选择ejs,我只想要一个简单的帮我填充数据的模板。github 文档 ejs.co

  • express:一个服务器端的基于 Node.js 的 JavaScript 开发框架。 官方文档 中文文档

  • mongoose:让NodeJS更容易操作Mongodb数据库 官网 安装教程

  • Node.js 官方文档

  • Node.js 中文文档

  • jade 模板引擎 官方文档

  • superagent 是个 http 方面的库,可以发起 get 或 post 请求。github

  • cheerio 大家可以理解成一个 Node.js 版的 jquery,用来从网页中以 css selector 取数据,使用方式跟 jquery 一样一样的。github

安装依赖

npm install PACKAGE_NAME --save 

$ npm install #安装 package.json 中的依赖

包管理工具

NPM:https://www.npmjs.org/ (官方)
CNPM:http://cnpmjs.org/http://npm.taobao.org/ (淘宝)

数据库

热门包

开发调试

社区

nxylene's People

Contributors

jaywcjlove avatar mortonfox avatar

Stargazers

Vini avatar  avatar Indrajith Bandara avatar Cuity avatar  avatar dong4j avatar  avatar jiahao li avatar yaobin avatar  avatar Wei avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.