节点本地主机正在运行,但无法正常工作

问题描述 投票:0回答:0

我尝试连接我的 mongodb 并运行网络浏览器,它看起来像:enter image description here 我清理缓存以确保端口不存在

`const express = require('express');
const mongoose = require('mongoose')
const postRoutes = require('./routes/post.routes');
const uri = 'mongodb+srv://sdoganguezel:<tTnpwNZPPF6qWLDK>@pwa.wbwrvum.mongodb.net/?retryWrites=true&w=majority'
require('dotenv').config();

const app = express();
const PORT = 3000;

app.use(express.json());
app.use('/posts', postRoutes);

 
// connect to mongoDB
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true });
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
    console.log('connected to DB');
});
 
//

app.listen(PORT, (error) => {
    if (error) {
        console.log(error);


    } else {
> console.log(`server running on http://localhost:${PORT}`);
    }
});
`
html node.js web localhost npm-start
© www.soinside.com 2019 - 2024. All rights reserved.