0

In my react project, within a component, I want to include a npm module like so:

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true});

This does work in regular node js, react however shows a TypeError: mongoose.connect is not a function. Trying import mongoose from 'mongoose' returns a TypeError: mongoose__WEBPACK_IMPORTED_MODULE_4___default.a.connect is not a function.

How do I use npm packages in a react app? Do I need meteor (I've heard of it, but I don't understand what it does)?

1 Answer 1

1

you can't use mongoose in the browser in anything other than validation => doc

Mongoose supports creating schemas and validating documents in the browser. Mongoose's browser library does not support saving documents, queries, populate, discriminators, or any other Mongoose feature other than schemas and validating documents.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Do you know how to access data from a mongodb from the browser?
you can't do that in the client side, you have to go through a backend like nodejs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.