Sequelize : How to config webpack? - node.js

I'm using react and node js. I want to use Sequelize to manage database with mysql.
So I have this tree with sequelize :
In my package config, I have this :
So when i do :
npm run seed
I want execute the code of sequelize in seed folder.
But I have an error in node console :
How can I correct this error ?
Thank you

Related

SvelteKit and Postgres implementation solution

Has anyone successfully deployed a SvelteKit app using npm pg to Netlify/Vercel/Cloudflare? My local dev implementation works just fine with how I have it set up ( db.ts file with a query function in lib/server, and then using endpoint actions and the load function in +page.server.ts files)
My build errors are as follows:
node_modules/pg-connection-string/index.js:3:18: ERROR: Could not resolve "url" node_modules/pg-connection-string/index.js:4:17: ERROR: Could not resolve "fs" node_modules/pg-pool/index.js:2:29: ERROR: Could not resolve "events" node_modules/pg-protocol/dist/parser.js:9:41: ERROR: Could not resolve "assert" node_modules/pg/lib/client.js:3:27: ERROR: Could not resolve "events"
And many of the above display a previous log message with something along the lines of:
✘ [ERROR] Could not resolve "buffer"
node_modules/safe-buffer/index.js:3:21:
3 │ var buffer = require('buffer')
╵ ~~~~~~~~
The package "buffer" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
I've been trying to get it to just build and it seems like it isn't able to use the pg package because it isn't a true node server environment. For each adapter it attempts to build with (except the node adapter) it refuses to build anything to do with the pg npm package. I could be wrong about the why, but my question about the how remains.
My hope is to avoid something like Prisma (which hasn't been working for me either) and I am trying to do this as "intended" meaning that I want to use SvelteKit as both the front end and the true backend. So an additional express server or the like is not the solution I'm looking for.
EDIT: I have also successfully deployed the app to Azure using the node adapter, but pg AND Postgres.js both do not work.

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

How to fix nodemon app crash after added mongoose

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?

Dependance Sequelize

I try to use Sequelize .. And I have problems :( . I don't know if I have a conflict with an other npm package ..
Like the tuto, I did :
npm install sequelize --save
npm install mysql2 -- save
In my react app, in "sequelizeYes" folder, I did :
import * as Sequelize from 'sequelize'
const seq = new Sequelize('galadat', 'root', '')
seq
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
export default seq
In app component, i call the file like this :
import('../sequelizeYes')
You can see on the picture differents errors in the console..
Do you have an idea ?
Did you require the module?
var Sequelize = require('sequelize');
var fs = require('fs');
If you shared the lines of code that the errors indicate it might help as well. It looks like several different files are having problems.
Sequelize is a nodejs module intended to be used in your backend. (server-side) It will not work on client-side (with libraries such as React) as it has dependencies to native NodeJS modules as based on your description that is what you're trying to do. If you're working on a web application and use for example express have a look here https://github.com/sequelize/express-example
As #Eric suggests, you should require sequelize on top of your code. So this should work:
var Sequelize = require('sequelize');
If the error persists, you should delete folder "node_modules" and reinstall dependencies using the command "npm install". Also you should make sure all errors are thrown because of sequelize import.
If the error still persists, you should make sure you try to manipulate the models in server-side code, as #archansel and #frenzzy suggest here: https://github.com/kriasoft/react-starter-kit/issues/976
The reason is referenced above by #razakj answer

Grunt: mongoimport task not found

I am trying to use mongoimport package to import data to my mongodb. I installed mongoimport package as per mongoimport's npm documentation.
It added following to my package.json:
"grunt-mongoimport": "^0.1.3"
My Gruntfile.js looks like this:
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-mongoimport');
grunt.initConfig({
//....some default init tasks
mongoimport: {
options: {
db : 'fullstack-dev',
collections : [
{
name : 'submitters',
type : 'json',
file : 'lib/config/seedData.json',
}
]
}
},
//...some more tasks after mongo import
}
And then I added this custom task to Gruntfile.js:
grunt.registerTask('dev:prepare', ['serve:init', 'mongoimport']);
And I run the following command:
grunt dev:prepare
The serve:init executes properly but when running mongoimport, I get:
Running "mongoimport" task
>> Error: not found: mongoimport
I am not getting what am I missing here?
Are you on Windows? You need to add mongodb/bin to your system PATH variable.
Add MongoDB to Windows PATH
Open a console window
Enter:
set PATH=%PATH%;C:\_PATH_\_TO_\_MONGODB_\bin
Log out and log back in.
Is mongodb installed ?
This npm module that you are referencing is merely a helper that will help you make a mongoimport query with grunt. Can you actually call mongoimport from the same console you're calling your grunt tasks from ?

Resources