NodeJS & MongoDB Development Environment
Atom IDE
https://atom.io
- Download
- Unzip and drag to installation location
- Open Atom
- Menu Bar -> Atom -> Install Shell Commands
- Open a terminal session
- atom . (opens atom in the current working directory)
- Menu Bar -> Atom Preferences
- Install -> Search and click Packages to find and install
- atom-beautify
- atom-jade
- json-converter
- jsonlint
- linter
- language-babel
- pretty-json
Node (manual) – not preferred
https://nodejs.org
- Download latest version
- follow installation instructions
NPM – Node Package Manager – not preferred
https://www.npmjs.com
- click button
- follow installation instructions
NVM – Node Version Manager – preferred
https://github.com/creationix/nvm
- scroll down to readme and installation instructions
- open terminal
- curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
- close terminal session
- open terminal
- nvm help
- nvm ls
- nvm install v6.5.0
- nvm uninstall v6.5.0
- nvm install node
- nvm use v6.5.0
- node -v
- node –version
Homebrew
https://brew.sh
- copy command line code to install homebrew
- open terminal
- /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
MongoDB
https://www.mongodb.com
- scroll to install using homebrew
- follow instructions
- brew update
- brew install mongodb
- sudo mkdir -p /data/db
- sudo chown /data/db
- mongod (starts mongo daemon)
- mongo (this is the client)
- show dbs (show databases)
- use
Mongo Commands
- use
creates it if it does not exist - db
shows the current db -
db.mytable.insert({“name”:”jd”,”age”:21})
creates table if it does not exist, inserts the json data
RoboMongo
https://robomongo.org
- download Robo 3T
- install Robo 3T
- Open Robo 3T
- Create Connection
- Direct
- localhost :: 27017
- mydb -> Collections -> mytable
- Create Connection
Json Server
https://github.com/typicode/json-server
scroll down page to install section
- npm install -g json-server
- mkdir serverdb
- cd serverdb
- from website, creae db.json as follows
[code language=”javascript”]
{
"posts":[
{
"id":1,
"title":"json-server",
"author":"typicode"
}
],
"comments":[
{
"id":1,
"body":"some comment",
"postId":1
}
],
"profile":{
"name":"typicode"
}
}
[/code]
- json-server –watch db.json
start json-server
Postman
https://www.getpostman.com
- download Postman
- install postman
- start json-server
- open postman
- GET localhost:3000/posts
- GET localhost:3000/comments
- GET localhost:3000/profile
Node Package Manager – install packages
https://www.npmjs.com
- search for readline
- scroll down to readline-sync
- scroll down to installation
-
mkdir -p mynodeproject
- cd mynodeproject
- npm init
defaults all the way - ls
- atom .
- npm install readline-sync –save
- ls
- view the package.json
readline-sync added to dependencies
-
Copy example from webpage into index.js
[code language=”javascript”]
var readlineSync = require(‘readline-sync’);
// Wait for user’s response.
var userName = readlineSync.question(‘May I have your name? ‘);
console.log(‘Hi ‘ + userName + ‘!’);
// Handle the secret text (e.g. password).
var favFood = readlineSync.question(‘What is your favorite food? ‘, {
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});
console.log(‘Oh, ‘ + userName + ‘ loves ‘ + favFood + ‘!’);
[/code]
- open terminal
- node index.js