How to fix nodemon app crash after added mongoose - node.js

I am setting up an environment with mongodb, node.js, express.js and mongoose. mongoDB is in its own container, and the same with the rest.
It all worked fine until I tried to add mongoose.
After this line was added
const mongoose = require("mongoose");
I got an error-message when a ran docker-compose up
Error-message
This is my package.json
Package.json
This is my dockerfile for the api
Dockerfile
Does anyone knwo how to fix this?

Related

troubles deploying with diigtal ocean node sequelize

Im trying to make a deploy in Digital Ocean when i try to make a migration using sequelize cli but wehn i do it
npx sequelize db:migrate
its says a error in the terminal and says
ERROR: Cannot find "/home/deploy/app/config/config.json". Have you run "sequelize init"?
then i tri using
npx sequelize init
and create all the folders (migrations - models - config - seeders, etc) THEN i move my migrations to the folder created to try to fix the issue, then in the config/config.json y config all the bd config, and try it again but says the same issue all the time
how can i fix that please i need to make this deploy can someone helps me?
I have solved it using
npx sequelize db:migrate WORKDIR /myapp/path

Router on NodeJS express

I'm creating a nodeJS application and i was starting my app with nodemon app.js, everything was working well but when i stopped to restart it was impossible to restart. I found nothing about that on internet.
For informations i followed the node postgres documentation for the project structure using async/await : https://node-postgres.com/guides/async-express
I'm stucked in that problem and can't understand why it happens, I just want to restart my projet
Thanks for your help and have a nice day !
error at launch
I replaced the following requirement: const Router = require('express-promise-router'); to: const Router = require('router');

How to connect Mongo DB in a webpack dev server

I would like to connect to Mongo DB using a webpack dev server. While the connection using the node mongodb driver and configuring in server.js is direct and straight forward, I am thinking of a way to do the same using webpack dev server in development (mainly for the hot loading advantage).
I understand that there is a way of achieving the same using a webpack middleware, but is there another easier and better way of doing it.
webpack dev-server is generally a simple Express or similar node.js server. It's essentially exactly the same as writing is on an express.js server.
npm install mongoose mongodb --save-dev
const mongoose = require('mongoose'); // Replace with import as desired
const mongoConnectString = 'mongodb://localhost/database-name-here';
mongoose.connect(mongoConnectString, (err) => {
if (err) {
console.log('Err, could not connect to the database.');
}
});
Replace the mongoConnectString as needed for developing or using databases that aren't local to your machine.

Connection to MongoDB via mongoose

I am using Gulp building system. When I try to connect to my local MongoDB using mongoose I got error mongoose.connect is not a function.
Connection code:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
Your code seems fine. Are you sure you correctly installed mongoose?
npm install --save mongoose
Your problem isn't that you're using mongoose directly in react ?
Mongoose is a node module: "elegant mongodb object modeling for node.js".

How to debug Mongoose and MongoDB in a MEAN stack?

I'm learning the MEAN stack and I'm using npm start to run my application. I have some issues with Mongoose and MongoDB but all I get is POST /page 500 63.925 ms - 961
This is the directory structure of my app, based on this tutorial:
HTML views/
Angular.js public/javascript/
Express.js routes/
Node.js app.js
Mongoose js models/, connected in app.js
Mongo db connected in app.js
What can I do to get helpful Mongoose and MongDB debug messages?
Using node-inspector is very helpful. This question and answer showed me how to set it up in my case.

Resources