express基礎介紹

來源:互聯網
上載者:User

express基礎介紹

一、安裝環境及準備工作
安裝node、npm、express、jade、less及supervisor
安裝node環境,官網:http://nodejs.org
安裝npm外掛程式管理工具,官網:https://npmjs.org
安裝express,官網:http://www.expressjs.com
安裝jade,官網:http://jade-lang.com
安裝less,官網:http://www.lesscss.net
安裝supervisor,使用:supervisor app.js
備忘:
npm install express (安裝在目前的目錄下)
npm install -g express  (安裝在全域)
node_modules包含檔案如所示:

二、基礎例子
app.js內容

var express = require('express');var app = express.createServer(    express.logger());app.configure(function(){    app.set('views', __dirname + '/views');    app.set('view engine', 'jade');    app.use(app.router);    app.use(express.bodyParser());    app.use(express.errorHandler({        dumpExceptions:true,showStack:true    }));});app.get('/',function(req,res){    res.render('index.jade',{title:'標題'});});app.listen(3000);

 

views目錄包含layout.jade和index.jade
layout.jade內容

!!!html    head        meta(charset='utf-8')        block headblock    body        block contentblock

index.jade內容

extends layoutblock headblock    title #{title}    include ../less/test.lessblock contentblock    h1= title    p Hello Moming ! Welcome to #{title}      include ../script/test.js

備忘:
less目錄包含test.less檔案
script目錄包含test.js檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.