NodeJs-Quick Start Guide and Quick Start Guide

Source: Internet
Author: User

NodeJs-Quick Start Guide and Quick Start Guide

About NPM:

Npm is a node. js package management and distribution tool. It allows javascript developers to share code and code snippets more easily, and it is convenient, convenient, and simple to manage the code you share through npm.

NodeJs installation and NPM Management

Install

Go to the official NodeJs website and download the installation package for installation. NodeJs also includes the NPM module by default. The latter must be updated to the latest version. -V: Check the version information. If yes, the installation is successful. Some versions do not support the case sensitivity of the read-v parameter. If an error is reported, the read-V parameter is capitalized.

node -vv4.4.4npm -v2.15.1

Update npm Module

node install npm -g

-G indicates global installation. All installed module files in windows are stored in the node installation directory or in the C: \ Users \ Administrator \ AppData \ Roaming cache directory.
Remove-g local installation. npm creates a node_modules directory under the current directory and stores the downloaded modules in it.

Uninstall

Use uninstall to delete a module from the node_modules directory

# Local uninstallation npm uninstall <name> # global uninstallation npm uninstall <name>-g

2. Create the first NodeJs Application

Use the express module to create an application.

First download the express Module

npm install -g expressexpress -V

Similarly, check whether the installation is successful. There are also two parameters:-e or -- ejs;-J or -- jshtml. Meaning:
-E, -- ejs add ejs engine support add ejs module engine support

-J, -- jshtml add jshtml engine support (defaults to jade) add jshtml template engine support

The new version of express does not support cmd command lines, so the above express-V will report an error: it is not an internal or external command, you need to download express-generator

Npm install-g express-generator

Then, you can use the express command globally. Select a folder (F: \ Project \ Nodejs) to create an application:

Express hello_world

Cd hello_world enters the project

Cd hello_world # view the directory structure dir # like this #2016/06/26 <DIR>. # <DIR> .. #2016/06/26 1,442 app. js # <DIR> bin #2016/06/26 331 package. json # <DIR> public #2016/06/26 <DIR> routes #2016/06/26 <DIR> views #2 files, 1,773 bytes #6 directories, 161,019,293,696 available bytes *

Note that there is a package. json file in which the dependencies attribute specifies the module on which the current project depends. Before starting, run npm install to download them:

Npm install

If the package. json file does not exist, an error is returned in this step:

npm ERR! install Couldn't read dependenciesnpm ERR! Windows_NT 6.1.7601

You can use npm ini to generate the default one. Here, the express hello_world command above has called this command internally, and the generated file content is similar to this:

{ "name": "hello_world", "version": "0.0.0", "private": true, "scripts": {  "start": "node ./bin/www" }, "dependencies": {  "body-parser": "~1.15.1",  "cookie-parser": "~1.4.3",  "debug": "~2.2.0",  "express": "~4.13.4",  "jade": "~1.11.0",  "morgan": "~1.7.0",  "serve-favicon": "~2.3.0" }}

You can also install the preceding template and receive the package. json file created. It is worth mentioning that the package. json file of an npm module contains far more information than the package. json file.

Wait until the dependent library is downloaded. After completion, add a node_modules folder to save the dependent library.

So far, the current application preparation is complete. Start the application:

Npm start

Enter 127.0.0.1: 3000 (default port) in the browser to access

Summary

In my personal experience, I hope to provide a reference for anyone who has created a nodeJs application from scratch.

The above is the node. js provided by the mini-editor. It is essential to get started with all the content of the introduction. I hope you can support more help ~

Related Article

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.