Installing NodeJS and MongoDB
Install the latest "Long Term Support (LTS)" version of Node.js. It can be downloaded from the URL https://nodejs.org/en/download. To verify you have Node.js and its package manager (npm), try running the commands:
node -v
npm -v
which should run and print out the version numbers of your node and npm programs.
What is npm???
npm makes it easy for Javascript developers to share the code that they've created to solve particular problems, and for other developers to reuse that code in their own applications.
nstalling stuff:
npm install
You probably got npm because you want to install stuff. That's what package managers do, they install stuff.
npm install blerg
installs the latest version ofblerg
. You can also giveinstall
a tarball, a folder, or a url to a tarball. If you runnpm install
without any arguments, it tries to install the current folder.This command can do a lot of stuff.
npm help install
will tell you more than you ever wanted to know about it.Showing things:
npm ls
The
npm ls
command shows what's on your system, and also what's available in the registry. The arguments are beautifully colored greps. For instancenpm ls installed
would show you what's installed on your system.npm ls installed marak
would show you all the packages installed on your system created by Marak.
npm help ls
for more info.Updating packages:
npm update
The
update
command does a few things.
- Search the registry for new versions of all the packages installed.
- If there's a newer version, then install it.
- Point dependent packages at the new version, if it satisfies their dependency.
- Remove the old versions, if no other package names them as a dependency.
So basically, update behaves a lot like a "standard" package manager's update command, except that it also checks to make sure that the new version isn't going to break anything before it points stuff at it.
You see, npm keeps you out of dependency hell.
Development:
npm link
The link command symlinks a package folder into your system, so that changes are automatically reflected. It also installs the
"dependencies"
and"devDependencies"
packages from your package.json file.This is one of the most useful tools for developing programs with node. Give your thing a name and a version in a
package.json
file. Specify a few dependencies and amain
module. Then runnpm link
, and go to town coding it and testing it out in the node repl. It's great.
Making a Package: The
package.json
file.The
package.json
file goes in the root of your package. It tells npm how your package is structured, and what to do to install it.Most of the time, you only need the
"name"
,"version"
, and"main"
fields (even for node-waf compiled addons).If you don't know json, then it's about time you learn it. It's pretty easy.
Install the current stable release of MongoDB from the website https://www.mongodb.org/downloads#production. Unless you direct it otherwise, MongoDB will store the database in the directory /data/db
(C:\data\db
on Windows). Make sure this directory exists and is writable by you before starting the database.
To verify you have MongoDB installed and working try starting it with the command:
mongod
"waiting for connections on port 27017"
. The mongod
doesn't exit until the database is shut down so you will want to either run this in its own window or in background.
You should be able to directly interact with the MongoDB database by running the command:
mongo