简单的 Nodejs jade 实现Hello world
来源:互联网 发布:威海商友网络怎么样 编辑:程序博客网 时间:2024/06/08 02:53
更多功能可去github查看下载
首先要安装几个扩展这里不讲怎么装了。
文件结构如下:
一定要注意路径
server.js
'user strict'var port = 8888;const express = require('express'), app = express(), bodyParser = require('body-parser'), path = require('path'), fs = require('fs');;app.set('views','./static/pages');app.set('view engine', 'jade');app.use(express.static(path.join(__dirname,'./static')));app.get('/image', function (req, res) { var files =fs.readdirSync('./static/images'); res.render('index',{ title:'标题' , contentTitle: 'Hello World', imgs:files, description:'我的图片' }) });app.get('*', function(req, res){ res.render('404',{}) });var server = app.listen(port, function () { var host = server.address().address; var port = server.address().port; console.log("网址访问路径 http://%s:%s", host, port);});
注意语句 block content
layout.jade
doctype html head meta(charset='utf-8') title #{title} include ./head body block content
head.jade
link(href="/css/main.css" rel='stylesheet')
index.jade
extends ../layout block content h1 #{contentTitle} p #{description} each img in imgs img(src="images/#{img}" class="row-img")
(可以加一个放js的地方,与css类似,此处不多说啦。)
main.css
h1 { color: red;}.row-img { width:140px; height:140px; margin:5px}
代码写完了,命令行进入项目server.js 所在目录
node server.js
打开浏览器查看
http://127.0.0.1:8888/image
0 0
- 简单的 Nodejs jade 实现Hello world
- NodeJs的安装 Hello World!
- 简单的hello world
- 简单的‘Hello World!’
- nodejs的第一个程序Hello World
- 无情的nodejs--hello world入门篇
- nodejs 2 hello world!
- 一个简单的"Hello World"
- 简单的hello world驱动
- hello world 简单的驱动
- hello world 的简单输入输出
- nodejs的模板引擎jade
- Nodejs学习二:Hello World
- Nodejs http server "Hello world"
- NodeJS入门之Hello world
- 搭建简单的OSGI的hello world
- wxWindows 最简单的Hello World程序
- 理解简单的Windows Hello World程序
- i/o——Java I/O底层
- ①单例模式
- centos一句话将数据导入远程mysql的表中
- akka clusterclient
- make install fping
- 简单的 Nodejs jade 实现Hello world
- eclipse实现远程debug
- C++_Primer 16.2 实例化
- hibernate数据库查询报错
- Add Two Numbers
- 2017网易内推-星际穿越
- c++函数默认参数
- Python API:OpenStack 隐藏深处的秘密
- Retrofit + RxAndroid的使用