node. js Getting Started Notes

Source: Internet
Author: User
Tags install mongodb

The first step is naturally installed, I am using webstorm this IDE, the installation is divided into 2 steps:

1, install Nodejs, download the installation version under Windows, note that the MSI is the extension, and then the next step, nothing to say, as follows:

32-bit msi:http://nodejs.org/dist/latest/

64-bit msi:http://nodejs.org/dist/latest/

2, install WebStorm8.0.3, as if will automatically find Nodejs installation path, do not need to configure what East;


Install Webstorm, start it, then create the project (NEW Project), Project type Remember to choose the node. js Express App, Next,

Options where the template engine, personally recommended to use EJS, do not use the default jade, based on the need to cooperate with other UI artists, do not let others learn a new thing,

Then click OK, you can start to work, note that the first time will download Express and template engine and other related JS files, time is longer, domestic environment ah ...


Another: Create the project, Bin/www file is the startup file; Routes directory is the controller file, the views directory is the view


The second step I was to install MongoDB, the installation process out of the question, I was directly on the console, in the C packing directory, run:

NPM Install MongoDB

The result is finished, Webstrom project still can't use MongoDB, later found to install it to the project directory,

Recommended in Webstrom's Tools menu = "Open Terminal, where NPM installation is performed

Note: A domestic image was found, the installation of MongoDB quickly, but could not recognize the express version information, so loaded MONGO I deleted the image,

2 ways to set up mirroring:

1. Command line installation:

NPM Config Set Registry http://registry.cnpmjs.org
NPM Info Underscore

2, directly edit the node installation directory under the NPMRC file, my file path in: C:\Program files (x86) \NODEJS\NODE_MODULES\NPM

Open with Notepad, add one line at the end: Registry = http://registry.cnpmjs.org


Then record the code that accesses MongoDB and outputs the data to the view page:

var MONGO = require ("MongoDB");/* GET home page. */router.get ('/', function (req, res) {    var server = MONGO. Server ("192.168.189.35", 27017, {});    var db = new MONGO. Db (' Mytestdb ', server, {safe:true});    var arr = [];    Db.open (err, client) {        if (err) {            throw err;        }        var collection = new MONGO. Collection (client, ' Mytestcoll ');        Collection.find (). ToArray (err, items) {            res.render (' index ', {title: ' Express Display ', data:items});    });});



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.