Difference between revisions of "MongoDB and NodeJs"
(→Installation) |
|||
Line 24: | Line 24: | ||
>brew services start mongo #start/stop/status | >brew services start mongo #start/stop/status | ||
</source> | </source> | ||
+ | |||
+ | =NodeJs-Mongo= | ||
+ | <source> | ||
+ | $ mkdir users => cd users | ||
+ | $ mkdir src | ||
+ | $ mkdir test | ||
+ | </source> | ||
+ | |||
+ | <source> | ||
+ | $ npm install request --save #url için | ||
+ | $ npm install --save mocha nodemon mongoose | ||
+ | </source> | ||
+ | mocha: unit test | ||
+ | nodemon: | ||
+ | mongoose : mongo db driver | ||
+ | |||
+ | |||
+ | ==Mocha - Unit Test== | ||
+ | |||
+ | '''test/create_test.js(test file):''' | ||
+ | <syntaxhighlight lang="javascript"> | ||
+ | const assert = require('assert'); | ||
+ | |||
+ | describe('Creating records',()=>{ | ||
+ | it('saves a user',()=>{ | ||
+ | assert(1+1 ===2); | ||
+ | }); | ||
+ | }); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | '''package.json file:''' | ||
+ | <syntaxhighlight lang="javascript"> | ||
+ | { | ||
+ | "name": "users", | ||
+ | "version": "1.0.0", | ||
+ | "description": "", | ||
+ | "main": "index.js", | ||
+ | "scripts": { | ||
+ | "test": "mocha" | ||
+ | }, | ||
+ | "author": "", | ||
+ | "license": "ISC", | ||
+ | "dependencies": { | ||
+ | "mocha": "^5.2.0", | ||
+ | "mongoose": "^5.3.10", | ||
+ | "nodemon": "^1.18.6", | ||
+ | "request": "^2.88.0" | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | <source> | ||
+ | $ npm run test | ||
+ | </source> | ||
+ | |||
+ | |||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | |||
+ | </syntaxhighlight> |
Revision as of 13:37, 8 November 2018
MongoDB
NodeJs
Installation
We will install :
- MongoDb
- Node
- Robomongo - editor
brew - package manager can be used on MacOs
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Mongo Installation:
>brew install mongo
>mongod
>sudo mkdir -p /data/db
>sudo chown -Rv rasimsen /data/db
>brew services start mongo #start/stop/status
NodeJs-Mongo
$ mkdir users => cd users
$ mkdir src
$ mkdir test
$ npm install request --save #url için
$ npm install --save mocha nodemon mongoose
mocha: unit test nodemon: mongoose : mongo db driver
Mocha - Unit Test
test/create_test.js(test file):
const assert = require('assert');
describe('Creating records',()=>{
it('saves a user',()=>{
assert(1+1 ===2);
});
});
package.json file:
{
"name": "users",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC",
"dependencies": {
"mocha": "^5.2.0",
"mongoose": "^5.3.10",
"nodemon": "^1.18.6",
"request": "^2.88.0"
}
}
$ npm run test