Acquaintance node.js (npm download process through the project depends on the package) acquaintance node.js (npm download process through the project depends on the package)

Acquaintance node.js (npm download process through the project depends on the package)

 

One, node.js acquaintance

       Simply put Node.js is running on the server side JavaScript.

       Node.js is a platform based on a built Chrome JavaScript run-time.

       Node.js is an event-driven I / O server-side JavaScript environment, based on Google's V8 engine, the V8 Javascript execution speed is very fast, very good performance.

       Node.js package manager npm, the world's largest repository of open source ecosystem.

       Node.js official website: https: //nodejs.org/en

       npm official website: https: //www.npmjs.com

      

1, install node.js

       Download the installation package from the official website, install v8.12.0 paper version, for example, follow the prompts to install the download is complete.

       Note: If the installation process to modify the default installation path, the path will have to be added to the modified environment variable system.

 

2, node.js Commands (cmd end effector)

       View node version: node -v

       View npm version: npm -v

       Environment into the node: node

       Exit node environment: twice ctrl + c

 

3, through downloads node.js npm used in the package, such as bootstrap and other jquery, the following steps:

       a, installed after node.js, switch to the command line cd to the project directory;

       b, initialize the project directory, it will automatically generate a file package.json to manage our package with the following command:

              npm init or npm init --yes

       C, dependent on the current project download package, such as bootstrap and jquery, commands are as follows:

              npm install jquery –S 或者 npm install jquery --save

              npm install [email protected] –S(--save) 或者 npm install jquery@3 –S(--save)

              note:

                     1) The default download the latest version, you can also bring a version number;

                     2) After the implementation of the project in order to increase the node_modules a folder that contains jquery file;

                     3) After Run package.json added to "dependencies": { "jquery": "^ 3.3.1"};

              Download bootstrap put on top of jquery bootstrap can be replaced, you can also specify a version, as follows:

    npm install bootstrap@3 –S 或者 npm install bootstrap@3 –save

       note:

           1) The default download the latest version, you can also bring a version number;

                     2) After executing the command project node_modules folder adds a bootstrap folder;

                     3) After performing package.json the "dependencies" value increases { "bootstrap": "^ 3.3.7",};

              PS: In the current project dependencies dependencies, the dependent packages are stored in a development environment in devDependencies.

              Summary: The project dependencies in all packages are placed node_modules folder.

       d, uninstall command: npm uninstall jquery -S

 

4, github does not allow uploading of more than 100M project, so upload projects without uploading node_modules folder.

       After node_modules manually delete a folder, package.json dependent packages still exists, execute the command in the terminal, you can automatically download all packages package.json the following command: 

       npm install

       So when you download a project from GitHub, into the project directory, the implementation of the project can be downloaded npm install dependent packages.

 

5, for example, package.json file in a project in the following key-value pairs:

  "scripts": {

    "dev": "node build/dev-server.js",

    "build": "node build/build.js"

  },

       So, we can perform npm run dev to open the node server, and then access the project; can perform npm run build order of projects compression and ugly of (js and css files are in a row, and the variables e, t, i and other single-letter representation).

       Note: The front-end server is, that node.js. Often used as the intermediate layer, to accept the request sent by the front page, the server sends a request to the background like python. Distal global variables are hung on the window object, node.js global variables hanging on global object.

 

6, the front end of three compression tools: webpack (used more), grunt, gulp.

 
 

Guess you like

Origin www.cnblogs.com/ruan-ruan/p/11671490.html