Open baremetals opened 4 years ago
when i remove these two lines: const storeUserController = require('./controllers/storeUser'); app.post('/users/register', storeUserController);
the server starts back up and the site works, but i cannot register i get "Cannot POST /users/register" response. which I am guessing is to do with not being able to store the user registration. or isit something else i am overlooking?
i sussed out what i did wrong.
I am on chapter 10 user creation, I am certain my code is right but the app engine will not start it keeps giving me this error:
[nodemon] app crashed - waiting for file changes before starting... [nodemon] restarting due to changes... [nodemon] starting
node index.js
[nodemon] restarting due to changes... [nodemon] startingnode index.js
/Users/kompetes/OneDrive - Baremetals Ltd/JavaScriptStudies/cleanblog/models/User.js:10 const User = mongoose.model('User', UserSchema); ^ReferenceError: UserSchema is not defined at Object. (/Users/kompetes/OneDrive - Baremetals Ltd/JavaScriptStudies/cleanblog/models/User.js:10:37)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (/Users/kompetes/OneDrive - Baremetals Ltd/JavaScriptStudies/cleanblog/controllers/storeUser.js:1:14)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (/Users/kompetes/OneDrive - Baremetals Ltd/JavaScriptStudies/cleanblog/index.js:14:29)****
at Module._compile (internal/modules/cjs/loader.js:1133:30)
[nodemon] app crashed - waiting for file changes before starting...
This is my code on the index page. I even downloaded your version just to compare but the error remains. my code:
const express = require('express'); / const path = require('path'); / const app = new express(); const ejs = require('ejs'); const mongoose = require('mongoose'); const bodyParser = require('body-parser'); const fileUpload = require('express-fileUpload');
const newPostController = require('./controllers/newPost'); const homeController = require('./controllers/home'); const storePostController = require('./controllers/storePost'); const getPostController = require('./controllers/getPost'); const newUserController = require('./controllers/newUser'); const storeUserController = require('./controllers/storeUser');
const validateMiddleWare = require('./middleware/validateMiddleware');
app.use(fileUpload());
mongoose.connect('mongodb://localhost/my_database', { useNewUrlParser: true }); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs'); / const BlogPost = require('./models/BlogPost.js'); / app.use(express.static('public'));
app.listen(4000, () => { console.log('app listening on port 4000'); });
app.use('/posts/store', validateMiddleWare);
app.get('/posts/new', newPostController); app.get('/', homeController); app.get('/post:id', getPostController); app.post('/posts/store', storePostController); app.get('/auth/register', newUserController); app.post('/users/register', storeUserController);