今天在编写JavaScript代码时,缺少了包express。
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello, world!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
npm install express
发生如下报错:
npm error code CERT_HAS_EXPIRED
npm error errno CERT_HAS_EXPIRED
npm error request to https://registry.npm.taobao.org/express failed, reason: certificate has expired
npm error A complete log of this run can be found in: C:\Users\VICTUS\AppData\Local\npm-cache\_logs\2024-09-23T04_26_15_084Z-debug-0.log
这时候需要配置tabao镜像。
npm config set registry https://registry.npm.taobao.org/
发现还是报错,原来在新的版本中,tabao镜像已经不再支持,为此需要下面代码:
npm config set registry https://registry.npmmirror.com
npm install express
added 65 packages in 2s
13 packages are looking for funding
run `npm fund` for details
问题成功解决;
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello, world!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});