Reputation: 1
For the below code
import pkg from 'express';
const { express } = pkg;
import dotenv from 'dotenv'
import { Connection } from './database/db.js';
import router from './routes/route.js';
dotenv.config();
const app = express();
app.use('/', router)
const PORT = 4000;
app.listen(PORT,() =>{
console.log(`server is running on port: ${PORT}`)
});
//parse the importted usrname and password
Connection(USERNAME, PASSWORD);
I tried imprting express using pkg import as required in latest import and added "type":modeule in package.json But the server is not recogninsing express as a function due to I'm having problem to use app.use() as well as it is also causing error in recogninsing
for router.js code is
import pkg from 'express';
const { express } = pkg;
const router = express.Router()
router.post('/signup',signupUser);
export default router;
Can you please suggest where I can i Do?
Upvotes: -1
Views: 39
Reputation: 25
Server.js
import express from 'express'
import dotenv from 'dotenv'
import cors from 'cors'
import connectDB from './database/db.js'
import adminRoutes from './admin/routes/adminRoutes.js'
dotenv.config()
connectDB()
const app = express()
const router = express.Router()
app.use(cors())
app.use('/api/', routes)
const PORT = 5000
app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`
)
)
Router.js
import express from 'express'
const router = express.Router()
router.post('/testApi', testApi)
export default router
Upvotes: 0