Build a REST API with Node, Express & MongoDB!

Bennett Dungan on August 01, 2019

In this project we will be creating a way for people to subscribe, update, retrieve and delete data on Youtube accounts. We’ll do this by coding a ... [Read Full]
markdown guide
 

Wow just great
I'd like to have a mantor like you !

 
 

thank you! Took me much long than anticipated haha

 

It's alright I always take a much longer time to write technical articles.

 

Nice and Good Explaination..!
Can you please tell me what next? i would like to upload this Api to website for-example: example.com/api/posts instead of localhost:3000/posts
how can i do that?
Thanks.

 

How can I solve a Corss origin?, I'm calling localhost:3000/subscribers/ endpoint through react application which is running on localhost:3001

 

Hi, Vicente ! You can solve cross origin setting a header in your server definition.

res.header("Access-Control-Allow-Origin", "YOUR-DOMAIN");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 

But if you want you can delegate that to a lib called "cors" that you can install: github.com/expressjs/cors#installa...

And that you can use simply by calling it as a Middleware.

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

It is important to remember that allowing cors without specifying a known domain could be dangerous since anyone would be able to reach your api, be careful and if you have any questions don't hesitate to ask :)

saludos, paisano !

 

Hey thanks man for some reason I was missing put my domain there, but now it's work fine.

Gracias por el support carnal =).

 

Was a great guide for a beginner
Liked it lot <3

 

I love this article, great job!

Found a small error in the catch for the update subscriber, it's missing the (err) parameter part.

Thanks!

 

Thanks for article, I was test your code it really work great!

 
 

Thank you very much.This is the easy-to-follow blogs for beginner like me.I really enjoy it.Keep doing ! :)

 

Great tutorial! May I know how or where can I deploy this API?

code of conduct - report abuse