node-express-mongoose-demo 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
node-express-mongoose-demo 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
node-express-mongoose-demo 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT License
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 Web应用开发
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-11-30

软件简介

Build Status Dependencies Code Climate Join Gitter Chat

Nodejs Express Mongoose Demo

This is a demo application illustrating various features used in everyday web development, with a fine touch of best practices. The demo app is a blog application where users can signup, create an article, delete an article and add comments etc.

Table of contents:

Boilerplate

Want to build something from scratch? use the boilerplate

Install

git clone git://github.com/madhums/node-express-mongoose-demo.git
npm install
cp .env.example .env
npm start

Then visit http://localhost:3000/

NOTE: Do not forget to set the twitter, google, linkedin and github CLIENT_IDs and SECRETs. In development env, you can set the env variables in .env and replace the values there. In production env, it is not safe to keep the ids and secrets in a file, so you need to set it up via commandline. If you are using heroku checkout how environment variables are set here.

Tests

npm test

Docker

You can also use docker for development. Make sure you run npm install on your host machine so that code linting and everything works fine.

npm i
cp .env.example .env

Start the services

docker-compose up -d

View the logs

docker-compose logs -f

In case you install a npm module while developing, it should also be installed within docker container, to do this first install the module you want with simple npm i module name, then run it within docker container

docker-compose exec node npm i

If you make any changes to the file, nodemon should automatically pick up and restart within docker (you can see this in the logs)

To run tests

docker-compose exec -e MONGODB_URL=mongodb://mongo:27017/noobjs_test node npm test

Note that we are overriding the environment variable set in .env file because we don't want our data erased by the tests.

Note: The difference between exec and run is that, exec executes the command within the running container and run will spin up a new container to run that command. So if you want to run only the tests without docker-compose up, you may do so by running docker-compose run -e MONGODB_URL=mongodb://mongo:27017/noobjs_test node npm test

License

MIT

展开阅读全文

代码

评论 (0)

加载中
更多评论
暂无内容
发表了博客
2016/04/09 16:25

express中配置mongoose

1:先新建一个congfig文件夹:在里面新建config.js mongoose.js  //config.js module.exports={ //配置数据库url     mongodb:"mongodb://localhost/test" }/**  * Created by 1 on 2016/4/9.  */  //mongoose.js     var mongoose=require('mongoose'); var config=require('./config.js'); module.exports=function(){     var db=mongoose.connect(config.mongodb);     require('../model/user....

0
0
发表于服务端专区
2016/12/13 11:30

Node--mongoose查询问题

在mongo shell中可以用sort,skip等查询来完成所需要的查询。 现用mongoose来查询时 ``` return new Promise(function (resolve, reject) { model.find({"field":"values"}, { "_id": 0, "__v": 0 }, function (err, data) { if (err) { reject(err); } else { resolve(data); } }) }) ``` 这样只能添加where条件,当需要分页,排序的时候发现可以这样使用达到效果 ``` var query = model.find({}, { "_id": 0, "__v": 0 }); qu...

0
0
发表了博客
2019/01/14 08:39

【node】mongoose的基本使用

1、安装mongoose npm install mongoose 2、启动数据库 mongod --dbpath d:\data\db 3、引入mongoose模块并连接数据库 const mongoose = require("mongoose"); mongoose.connect("mongodb://127.0.0.1:27017/test1",function(err) { if(err){ console.log('连接失败'); }else{ console.log("连接成功") } });   4、创建表以及字段类型 const User = mongoose.model("user",{ na...

0
0
2020/11/26 10:44

express中安装配置mongoose

1:先新建一个congfig文件夹:在里面新建config.js mongoose.js  //config.js module.exports={ //配置数据库url     mongodb:"mongodb://localhost/test" }/**  * Created by 1 on 2016/4/9.  */  //mongoose.js     var mongoose=require('mongoose'); var config=require('./config.js'); module.exports=function(){     var db=mongoose.connect(config.mongodb);     require...

0
0
发表于大前端专区
2020/09/27 14:45

Node express html

# 创建Nodejs项目 - npm init # 加入Express依赖 - npm install express ---save # 创建index.js ```js var express = require('express'); var path = require('path'); var app = express(); app.use(express.static(path.join(__dirname, 'public'))); var server = app.listen(8081, function () { var host = server.address().address var port = server.address().port console.log("应用实例,访问地址为 http://%s:%s...

0
0
发表了博客
2019/06/24 11:24

node-- express()模块

1、代码分析 var express = require('express'); var app = express(); app.get('/', function(req, res){ res.send('hello world'); console.log('hello world'); }); app.listen('8808'); require() 用于在当前模块中加载和使用其他模块;此方法是模块的基础,使用中大概有路径的概念就行。PS:JS文件可以去掉".js"后缀    exports 表示模块的导出对象,用于导出模...

0
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部