RESTful API From Scratch Using Node, Express and MongoDB
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they were following when their Express and Mongoose code stopped working, such as nodemon errors, empty results, MongoDB connection failures and an empty req.body.
Recommended by 0 people across 0 different months, 2017 to 2017.
What it is
A roughly hour-long tutorial from Traversy Media that builds a REST API from scratch with Node.js, Express and MongoDB (via Mongoose). It covers GET, POST, PUT and DELETE routes over JSON for a bookstore app, typed out by hand without generators.
What people said
Cites Chris · 2017-02 · Stack Overflow · on “Nodemon index.js”
I'm brand new to nodemon. After following the steps on this video at 12:01 [this video] , I get the following errors when trying to run my app using nodemon: [LINK] HERE IS THE APP.JS file: var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); // Connect to Mongoose mongoose.connect('mongodb://localhost/ChatbotService') var db = mongoose.connection; app.get('/', function(req, res){ res.send('Hola4'); }); app.listen(8601); console.log('Running on port 8601...'); HERE IS THE PACKAGE.JSON FILE: { "name": "chatbot", "version": "1.0.0", "description": "chatbot app", "main": "index.js", "scripts": { "test": "echo \"Error: no
Cites Chris · 2017-02 · Stack Overflow · on “MongoDB express app showing empty array”
I am new at MongoDB / Node.js / express. I'm setting up an app following this: [this video] I've created a db called "chatbot" and 2 collections within "chatbot": "countries" and "populations". However, when I try to run the app to display the countries that I created in the shell, I get nothing but an empty array. Here is the collection "countries": > db.countries.find() { "_id" : ObjectId("58a0c3234d9ba38dcbe1769d"), "name" : "Afghanistan" } { "_id" : ObjectId("58a0c3844d9ba38dcbe1769e"), "name" : "Andorra" } Here are my app files: package.json file: { "name": "chatbot", "version": "1.0.0", "description": "chatbot app", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" &
Cites Raman · 2017-03 · Stack Overflow · on “Node.js req.body is empty when using POST method”
I'm really new to using REST and Express and I've been following this tutorial [this video] on REST API. Here is my app.js code: var express = require('express'); var bodyParser = require('body-parser'); var mongoose = require("mongoose"); var app = express(); var port = parseInt(process.env.PORT, 10) || 3000; app.use(bodyParser.urlencoded({ extended: true})); app.use(bodyParser.json()); Genre = require('./models/genre'); //Connect to mongoose mongoose.connect('mongodb://localhost/bookstore'); var db = mongoose.connection; app.listen(port); console.log('Running on port 3000\n\n'); app.post('/api/genres', function(req, res){ console.log(req.body); var genre = req.body; Genre.addGenre(genre, functi
Cites AbdallahRizk · 2017-08 · Stack Overflow · on “Why I cant retrive data from mongodb in my simple web application?”
I am trying to connect mongodb to my express nodejs web application. I am fresh new to nodejs. I am following this [this video] tutorial video but I couldn't complete it due to the connection of mongodb. the app.js code I have: var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); Genre = require('./models/genre'); let conn = mongoose.connection; conn.openUri('mongodb://localhost/bookstore'); conn.on('error', err => console.error('mongodb connection error', err)); conn.on('connected', () => console.info(`Connected to mongodb`)); conn.on('disconnected', () => console.info('Disconnected from mongodb')); app.get('/', funct
Cites AbdallahRizk · 2017-08 · Stack Overflow · on “why mongodb doesnt connect with my nodejs simple application?”
I am trying to connect mongodb to my express nodejs web application. I am fresh new to nodejs. I am following this tutorial video [this video] but I couldn't complete it due to the connection of mongodb. the app.js code I have: var express = require('express'); var app = express(); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); Genre = require('./models/genre'); mongoose.connect('mongodb://localhost/bookstore'); mongoose.connection.on('error', (err) => { console.error('mongodb connection error', err); }); mongoose.connection.on('connected', () => { console.info(`Connected to mongodb`); }); mongoose.connection.on('disconnected', () => { console.info('Disconnected from