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

Homebrew

https://brew.sh

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

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
{
"posts":[
{
"id":1,
"title":"json-server",
"author":"typicode"
}
],
"comments":[
{
"id":1,
"body":"some comment",
"postId":1
}
],
"profile":{
"name":"typicode"
}
}
  • 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

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 + '!');
  • open terminal
  • node index.js
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s