这篇文章主要介绍“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 || 3000
var app = express()
app.set('views', './views');
app.set('view engine', 'jade')
app.listen(port)
console.log('server started')
//index page
app.get('/', function(req, res){
res.render('index',{
title : 'index page'
})
})
//detail page
app.get('/movie/:id', function(req, res){
res.render('detail',{
title : 'detail page'
})
})
//admin(add) page
app.get('/admin/movie', function(req, res){
res.render('admin',{
title : 'admin page'
})
})
//list page
app.get('/admin', function(req, res){
res.render('list',{
title : 'list page'
})
})
index.jade, detail.jade, admin.jade, list.jade
doctype
html
head
meta(charset="utf-8")
title #{title}
body
h2 #{title}
dos
node app.js
see on explorer
index page: http://localhost:3000 detail page: http://localhost:3000/movie/1 admin(add) page: http://localhost:3000/admin/movie list 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 m
ust be installed separately.
A: http://www.tuicool.com/articles/vaiyMb
var bodyParser = require('body-parser');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.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怎么配置”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/jayronwang/blog/355553