Ubuntu下用webstorm开发Nodejs(二)
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu下用webstorm开发Nodejs(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、nodejs+express開發項目
2.一旦npm安裝依賴包完成,項目根目錄下會出現node_modules的子目錄。項目配置所需的express包都存放于這里。
說明:還有更簡單的操作方式,直接輸入命令:npm install express,會出現如下畫面直到安裝完成
3.進行GET請求調用
app.js是這個項目的入口文件,通過router轉發GET請求進行
進入router/index.js
var express = require('express'); var router = express.Router();/* GET home page. */ router.get('/', function(req, res, next) {res.render('index', { title: 'Express' }); });module.exports = router;可以看到通過router.get發起get請求,返回結果如下
<!DOCTYPE html> <html><head><title><%= title %></title><link rel='stylesheet' href='/stylesheets/style.css' /></head><body><h1><%= title %></h1><p>Welcome to <%= title %></p></body> </html>4.進行POST請求調用
進入router/user.js,修改user.js為如下內容
var express = require('express'); var router = express.Router();/* GET users listing. */ router.post('/', function(req, res, next) {res.send('respond with a resource'); });module.exports = router;返回結果為
respond with a resource二、安裝postman調試工具
1.下載postman,鏈接: https://pan.baidu.com/s/1PbWBxs8_15jiT0DEOsBSMg 提取碼: 2f9v
2.解壓安裝
sudo tar -xzf 2018Postman-ubuntu-x64-6.2.7.tar.gz此時,在當前目錄出現一個Postman文件夾。
啟動Postman
./Postman/Postman3.創建啟動圖標 每次進入Postman目錄很不方便,可以創建一個啟動項。
建立軟鏈接
創建啟動項文件
sudo vim /urs/share/applications/postman.desktop寫入:
[Desktop Entry] Encoding=UTF-8 Name=Postman Exec=/urs/bin/postman Icon=/home/c/Downloads/Postman/Postman/app/assets/icon.png Terminal=false Type=Application Categories=Development;在dash里就可以搜索到Postman。
三、調試GET請求和POST請求
1.啟動nodejs
在ubuntu終端輸入命令
node app.js終端看到日志輸出
Listening on port 33332.打開postman
總結
以上是生活随笔為你收集整理的Ubuntu下用webstorm开发Nodejs(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ubuntu下使用WebStorm开发n
- 下一篇: 【问链-EOS公开课】第八课 EOS 数