Setup/Configure NodeJS, MongoDB, Mongoose with Visual Studio Code

The intent of the article is to provide a step-by-step instruction to write a “Hello World” application using NodeJS, MongoDB, Mongoose in “Visual Studio Code” editor.  The article also assumes that you are aware of the concepts behind using a MEAN stack for developing JavaScript based web application and their advantages etc.,

Step 1 (Install Node):

Download and Install NodeJS from this link

Step 2 (Install Mongo DB):

Download and Install Mongo DB from this link (make sure that you follow the instructions on the page to setup the Windows service and test it, before proceeding further).

Step 3 (Setup development environment):

  1. Fire up “Visual Studio Code” and use the “Open Folder” option to point to “any” folder where you plan to create/store the project specific files (to be created as part of the “hello world” application).
  2. Use the “File-> New File” option (or the “New File” in the Explorer window) to create a new file and name it as “main.js“.
  3. Launch the “Integrated Terminal” window from “View->Integrated Terminal”.
  4. Type “npm init” (as provided in the below image and keep pressing “enter” for all questions prompted to assign the default values, which can be overridden by providing a custom value, if preferred). integratedterminal
  5. When completed it will create the “package.json” file along with all the default settings.
  6. Open up the “package.json” and add the dependencies for mongodb and mongoose (as highlighted below) and save the file:packagejson
  7. In the “Integrated Terminal” type “npm install” and hit enterdependencyinstall
  8. After the dependencies are installed by npm, you should see the “node_modules” folder on the explorer window (which contains all the dependent npm modules required for mongodb and mongoose to run in nodejs ecosystem):nodemodules

Continue reading

3,317 total views, no views today