Creating a Simple Node.js project with MongoDB connectivity (Part 1)
For beginners who would love to have a short intro about why Node has become a raving feature lately, let's start off with elucidating its basic features here.
- It's an open source server framework that enables developers to obtain full certification to modify the script as desired.
- Totally free - Talk about not having to input all that messy credit card info to have access to the script.
- No need to hassle about platform prerequisites. Node has been proven to run on most of the renowned platforms such as-
- Mac OS X
There's just a vast arena of facts which can be discussed under node.js. But let's pause here and move onto the actual implementation of Node on your machine.
I've taken a simple example on creating a system called "studentSystem" which we'll be developing to create, update, view and delete student records. The following installation of Node.js will be focused on this studentSystem directory, though within this blog's scope, we'll be focusing on the installation of Node.js itself. You can refer to more information on how to format and create pages for your studentSystem in my next blog.
- Download Node.js and simply execute the installer.
- Create a folder into which you choose to store all your node project related files
- I have created a folder named node inside my F:\NodeJS directory.
- Install Express-Generator
- This is an application generator tool application generator tool which can be used to quickly create an application skeleton.
- In order to install this application generator tool,
- cd into the node folder that you just created and execute the following command
- F: \NodeJS\node>npm install –g express-generator
- F: \NodeJS\node>express studentSystem
- If you check out the package.json file, most of the dependencies will have been already created for you. Now since we're trying to manipulate data using mongo db, we need to add this dependency to the package.json dependencies as well.
"start": "node ./bin/www"
- Install dependencies
- cd to the studentSystem directory and execute the following command.
- “F: \NodeJS\node\studentSystem>npm install”
- Create a new data folder inside studentSystem directory using the mkdir command on the command prompt.
- “F: \NodeJS\node\studentSystem >mkdir data”
- Then type “F: \NodeJS\node\studentSystem>npm start”
- Open the browser and go to http://localhost:3000- This will display the Express welcome page
- Once this page is displayed, you can be assured that you have successfully installed Node. CONGRATULATION!
- Now you can proceed onto creating your actual student System.