To do with the background image preview express

 

 1. Installation express modules

  Command line input npm install express -g

  After entering the express -V find the version, suggesting 'express' is not an internal or external command, operable program run. Because in the isolated express4.x command tools, all you need to install express-generator.

  Command line, type: npm install -g express-generator, that is, the installation was successful.

  After entering the express -V, still prompts 'express' is not an internal or external command, operable program, but also need to configure the environment variables. Turn on the computer, the system Properties - Advanced System Settings - environment variables; variables in the system, the new NODE_PATH, the value of D: \ install \ nodejs \ node_global (global path), the "% NODE_PATH%" path back to the value of the variable i.e. can.

Now close the cmd window reopens (not otherwise still prompt internal and external commands). Input express -V, there have been

Said that it has successfully installed, the cmd command line enter the code below: express --version

4.16.1 appear

 2. Create express project, initialize cmd command:

NodeJSProject md // md here is to create a new file named

NodeJSProject cd // into the folder you just created

express albumServer // albumServer the project name

Display files that have been created in entering albumServer

 

cd albumServer

After npm install folder:

3. Start the server

  Elevation start

  After a successful start, the terminal will output node ./bin/www 

  Visit http: // localhost: 3000 /

 Adding a request in index.js

router.get('/a', function(req, res, next) {
   res.send('hello');
 });
Restart the project after viewing in a browser (in debugging Node.js application, as long modify the js file, you need to Ctrl + C to stop running, and then re-run, js files modified to take effect.):

4. By installing nodemon, let Node.js application to automatically restart

   (1) global installation:

npm install nodemon -g

(2) New nodemon.json file in the project directory and add the code below:

{
    "restartable": "rs",
    "ignore": [
        ".git",
        ".svn",
        "node_modules/**/node_modules"
    ],
    "verbose": true,
    "execMap": {
        "js": "node --harmony"
    },
    "watch": [

    ],
    "env": {
        "NODE_ENV": "development"
    },
    "ext": "js json njk css js "
}

(3) first open app.js, the last line module.exports = app; Zhushidiao, then add the following code to change it back again when the other line item.

var debug = require('debug')('my-application');
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
    debug('Express server listening on port ' + server.address().port);
});

package.json start items in the following code is modified

Run npm start to run nodemon, the results being given:

 

This is shown in the online search for some reason when Ben collapse, nodemon not restart automatically, this information will be output: [nodemon] App Crashed - Waiting for File Changes the before Starting ...

 The reason is due to the third step, the app.js into the original code can be run properly

  operation result:

 

 

 

Guess you like

Origin www.cnblogs.com/yina-526/p/11050427.html