[0] npm run server exited with code SIGINT [1] npm run client exited with code SIGINT
when i join router to my express and make a separate file it showing this kinda error that it couldn’t found routes
this is Express
file
import express from 'express';
import products from './data/products.js';
import dotenv from 'dotenv'
dotenv.config();
import connectDb from './config/db.js';
import productRoutes from './routes/productRoutes.js';
const port = process.env.PORT || 5000;
connectDb();//Mongo Connection
const app = express();
app.get('/', (req, res) => {
res.send('API is running...');
});
app.use('/api/products', productRoutes)
app.listen(port, () => console.log(`Server running on port ${port}`));
This is my productRoute.js
import express from 'express';
const router = express.Router();
router.get('/', (req, res) => {
res.json(products);
});
router.get('/:id', (req, res) => {
const product = products.find((p) => p._id === req.params.id);
res.json(product);
});
export default router;
a solution where i could resolve this error
New contributor
Siddik Mulla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.