nodejs tutorial怎么配置
这篇文章主要介绍"nodejs tutorial怎么配置",在日常操作中,相信很多人在nodejs tutorial怎么配置问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"nodejs tutorial怎么配置"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
see version
node --version
helloworld.js
var http = require('http'); server = http.createServer(function (req, res) { res.writeHeader(200, {"Content-Type": "text/plain"}); res.end("Hello World\n"); }) server.listen(8000); console.log("httpd start @8000");
run on DOS
node helloworld.js
enter the url in explorer
http://localhost:8000/
you will see "Hello World"
npm:
node.js+express.js+monent.js
mongodb+mongoose
jade
Bower:
jQuery
Bootstrap
npm install express jade moment mongoose mongodb
Q: error enoent stat
A: C:\Users\Administrator\AppData\Roaming\ 在这个目录建立npm文件夹
app.js (入口文件)
var express = require('express')var port = process.env.PORT || 3000var app = express()app.set('views', './views');app.set('view engine', 'jade')app.listen(port)console.log('server started')//index pageapp.get('/', function(req, res){ res.render('index',{ title : 'index page' })})//detail pageapp.get('/movie/:id', function(req, res){ res.render('detail',{ title : 'detail page' })})//admin(add) pageapp.get('/admin/movie', function(req, res){ res.render('admin',{ title : 'admin page' })})//list pageapp.get('/admin', function(req, res){ res.render('list',{ title : 'list page' })})
index.jade, detail.jade, admin.jade, list.jade
doctypehtml head meta(charset="utf-8") title #{title} body h2 #{title}
dos
node app.js
see on explorer
index page:http://localhost:3000detail page:http://localhost:3000/movie/1admin(add) page:http://localhost:3000/admin/movielist page:http://localhost:3000/admin
--------------------------
安装bower(全局global)
npm install bower -g
安装bootstrap(依赖jquery)
bower install bootstrap
A: Bower : ENOGIT git is not installed or not in the PATH
Q:安装git
npm install body-parser
Q:
(like bodyParser) is no longer bundled with Express and must be installed separately.
A: http://www.tuicool.com/articles/vaiyMb
var bodyParser = require('body-parser');// parse application/x-www-form-urlencodedapp.use(bodyParser.urlencoded({ extended: false }))// parse application/jsonapp.use(bodyParser.json())
npm install underscore
Q: errno:10061 由于目标计算机积极拒绝,无法连接。
Q: cannot find module 'regexp-clone'/'sliced'/'mpath'/'ms'/'mquery'...
A:
npm install regexp-clone sliced mpath ms mquery hooks mpromise muri
以上都是mongoose安装包,可能是由于没有把mongoose安装好造成
到此,关于"nodejs tutorial怎么配置"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!