0

I am running command node index.js and getting below error:

node:internal/modules/cjs/loader:1137 throw err; ^

Error: Cannot find module '../models/User' Require stack:

/home/ubuntu/travel-community/server/routes/auth.js /home/ubuntu/travel-community/server/index.js at Module._resolveFilename (node:internal/modules/cjs/loader:1134:15) at Module._load (node:internal/modules/cjs/loader:975:27) at Module.require (node:internal/modules/cjs/loader:1225:19) at require (node:internal/modules/helpers:177:18) at Object. (/home/ubuntu/travel-community/server/routes/auth.js:4:14) at Module._compile (node:internal/modules/cjs/loader:1356:14) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Module.load (node:internal/modules/cjs/loader:1197:32) at Module._load (node:internal/modules/cjs/loader:1013:12) at Module.require (node:internal/modules/cjs/loader:1225:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/ubuntu/travel-community/server/routes/auth.js', '/home/ubuntu/travel-community/server/index.js' ] } Node.js v18.19.1

I have checked and files are in right place. Below is the configuration:

ubuntu@ip-172-31-21-235:~/travel-community/server$ ls

config index.js models node_modules package-lock.json package.json routes

ubuntu@ip-172-31-21-235:~/travel-community/server$ cd routes/
ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ ls

auth.js

ubuntu@ip-172-31-21-235:~/travel-community/server/routes$ cd ..
ubuntu@ip-172-31-21-235:~/travel-community/server$ ls

config index.js models node_modules package-lock.json package.json routes

ubuntu@ip-172-31-21-235:~/travel-community/server$ cat index.js

const express = require('express'); const connectDB = require('./config/db'); const authRoutes = require('./routes/auth');

const app = express(); connectDB();

app.use(express.json());

app.use('/api/auth', authRoutes);

const PORT = process.env.PORT || 5000; app.listen(PORT, () => console.log(Server running on port ${PORT}));

Can someone please help.

I am using AWS Ubuntu 24 (free tier).

0

You must log in to answer this question.

Browse other questions tagged .