nodejs 起介面服務

2022-09-13 17:15:10 字數 986 閱讀 6870

首先在d盤新建個資料夾:nodejswebserver

然後在此處開啟win命令列:

node -v 檢視是否正確安裝了nodejs

node init 初始化專案, 可以直接按 enter 鍵,一直到它跑完

npm install express 安裝express框架

npm install body-parse --s**e 如果時post請求,需安裝這個

// 引入 express 模組);

// 定義方法

// get 請求

'/', function (req, res));

// post 請求

// 需要引入 bodyparser 方法

var bodyparser = require(

'body-parser');

));'/get_num'

, function (req, res));

// 監聽埠

3000

, function ())

;**

python 測試:

# coding=utf-8

import requests

data =

res = requests.post(

'', data=data)

print

('結果:'

nodejs 建立服務

一些核心模組 var http reqire http 引用網路資訊構建模組 var fs require fs 引用檔案操作模組 var path require path 引用操作檔案路徑模組 第三方模組 var express require require 引用express 第三方模組 v...

nodejs 開發小程式介面

1.開發前準備 安裝nodejs npm 1 建立乙個最簡單的專案 mkdir expressnpm install g express generatorexpress helloworld 現在在express資料夾下就出現了helloworld專案 cd helloworld npm inst...

用NodeJs設計GET POST介面

postroominfo const express require express var server express server.listen 8080 server.get getmsg req,res postroominfo then res 如果要用body paser處理這些pos...