npm安装express及查看版本,基本使用

it2023-02-23  82

1.首先确定你已经安装了 Node.js,然后去你创建的项目目录下打开命令窗口,执行sudo npm install express -g 2.执行npm list express查看版本 3.在项目下新建一个server.js文件,输入以下代码:

const express = require('express'); const app = express(); app.get('/', function(req, res) { res.send('<h1>22222222222222222</h1>') }) app.listen(9999) 在命令行工具中运行node server.js,然后打开浏览器窗口,输入:localhost:9999,如下图:

在js文件中输入:

var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {'Content-type': 'text/plain'}); response.end('111111111111111111111'); }).listen(8888);

在命令行工具中运行node server.js,然后打开浏览器窗口,输入:localhost:8888,结果如下图:

最新回复(0)