知乎专栏 | 多维度架构 |
目录
neo@MacBook-Pro ~ % mkdir node neo@MacBook-Pro ~ % cd node neo@MacBook-Pro ~/node % npm install express --save neo@MacBook-Pro ~/node % npm list express /Users/neo/node └── express@4.16.3
npm install body-parser --save npm install cookie-parser --save npm install multer --save
echo 'node_modules' > .gitignore
Hello world 测试程序
neo@MacBook-Pro ~/node % cat demo.js var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello World'); }) var server = app.listen(8080, function () { var host = server.address().address var port = server.address().port console.log("应用实例,访问地址为 http://%s:%s", host, port) })
neo@MacBook-Pro ~/node % node demo.js 应用实例,访问地址为 http://:::8080
浏览器访问 http://localhost:8080 将看到 Hello World 字符串