Under Nodejs Express from installation to operation of the entire process

Source: Internet
Author: User

installation process:NPM INSTALL-GD Expressnpm install-g express-generatorexpress-v//view version, now generally 4.x seriesExpress Ejs MyApp//Create a Ejs template projector Express myapp//this creates a jade template that has been successfully tested, whether Jade,ejs can be accessed through the following methods. //Enter the App.js file for modification:App.use (Express.static (Path.join (__dirname, ' Public ' ));
changed to: App.use (express.static (Path.join (__dirname, ' views ' )); / * View engine Setup environment variable settings, modified to the above situation, the following can not be modified, under normal circumstances can not modify * /app.set (' views ', Path.join (__dirname, ' views '));var Ejs = require (' Ejs ');app.engine ('. html ', ejs.__express);App.set (' View engine ', ' html ');The original 3 lines of this can be replaced;The following actions are followed:CD MyAppNPM Install//installation dependentNPM Start//Turn on serverEnter bin/www modify port to:Browser Input: http://localhost can access, at the same time, in the Views folder to write HTML can also be written in the address bar: http://localhost/hello.html such forms to access. since the above path has been modified, you should pay attention to the problem of css/js/img these paths in the background development. due to the system default access to public, if the requirements of security can be tested after the views to public, so the path needs to be noted:/javascripts/style.js Yes, is to add a/, while you are in the editor is required. /public/specific is what reason, I also do not know, may be the server different reason.

Under Nodejs Express from installation to operation of the entire process

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.