matthoiland / restful-api-demo

Code from the video titled "Building a RESTful API in 5 Minutes"
115 stars 45 forks source link

Cannot POST #7

Open michaelsboost opened 7 years ago

michaelsboost commented 7 years ago

I followed your tutorial on YouTube and I had no problem with the GET request but I haven't been able to POST to it with PostMan.

So I did a git clone of this repo just to make sure all the code is exactly the same as yours and I still have the same problem.

Console says...

SyntaxError: Unexpected token n
    at Object.parse (native)
    at parse (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/lib/types/json.js:88:17)
    at /Users/user/Desktop/restful-api-demo/node_modules/body-parser/lib/read.js:116:18
    at invokeCallback (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
    at done (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
    at IncomingMessage.onEnd (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:307:7)
    at emitNone (events.js:67:13)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:441:9)

With all the modules installed with the latest version console says....

Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
SyntaxError: Unexpected token n
    at Object.parse (native)
    at parse (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/lib/types/json.js:88:17)
    at /Users/user/Desktop/restful-api-demo/node_modules/body-parser/lib/read.js:116:18
    at invokeCallback (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:262:16)
    at done (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:251:7)
    at IncomingMessage.onEnd (/Users/user/Desktop/restful-api-demo/node_modules/body-parser/node_modules/raw-body/index.js:307:7)
    at emitNone (events.js:67:13)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:441:9)
    at process._tickCallback (node.js:355:17)
rijdz commented 7 years ago

just write promise before connecting mongoose in server.js

//MongoDB mongoose.Promise = global.Promise; mongoose.connect('mongodb://localhost/rest_test');