简体   繁体   English

node.js 标识符“express”已经声明

[英]node.js Identifier 'express' has already been declared

I am new with node.js , this is the first project that I am testing to execute, and I have an issue.我是node.js的新手,这是我正在测试执行的第一个项目,但我遇到了问题。 I review and comment and delete express but it is not solving.我审查和评论并删除快递,但它没有解决。

const express = require('express');
const app = express();
require('dotenv').config()
const mongoose = require('mongoose')
const dadosRouter = require('./routes/data')

mongoose.connect(process.env.MONGO, { useNewUrlParser: true })
const db = mongoose.connection
db.on('error', (error) => console.error(error))
db.once('open', () => console.log('Conecting db'))

app.use(express.json())

app.set("view engine", "ejs");
app.use(express.urlencoded({ extended: false}))


app.use('/data', dataRouter)

app.get('/', (req, res) => {
  res.send("Opening")
})

app.listen(port, ()=> {
  console.log(`Rodando servidor pelo localhost $(3000)`)
});
app.listen(3000, () => console.log('Server started')) 

I have this error我有这个错误

const express = require('express')
  ^

SyntaxError: Identifier 'express' has already been declared

Issue is you are calling the server twice.问题是您两次调用服务器。

// Remove this
app.listen(port, ()=> {
  console.log(`Rodando servidor pelo localhost $(3000)`)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM