I have a pretty large MongoDB server running on my local machine, I know how to create an API using Express & Node.js and know how to use routes, etc. But I only know how to add new data to a route using the POST method. My database has tens of thousands of entries in different collections and so it would be impossible to add them all manually.
I wanted to know if there was a way to quickly convert my entire mongodb local database into an API with Express so I can access it client-side from my React.js application.
Related
I have created a NodeJS project where I have saved the data in a file data.js. It is saved in a server in a local host and I can use it as an API call.
Now I would like to convert this project using MongoDB as the backend to make it more dynamic. I have fetched data using React Hooks in the HomeScreen Page.
Do I need to change the React Hook and Fetching data(axios) Code??
You do not need to change your React code if you ensure your Nodejs API still provides same data in same format as before. Just need to update backend nodejs code to store and fetch details from mongodb instead of the data.js file.
Just Use MongoDB Queries to fetch details and send it in the response like as you were sending before from data.js. The difference would be now is you will be storing your data in MongoDB collections and read it from collections according to your requirements.
I'm building a website where users can upload images
as a information to server and the admin responds accordingly.
Which tools/modules I need to use and what's the overall process if
I'm using Node js with express at backend. The database I'm thinking to use is MySQL but can also go with MongoDB if the overall
process is simpler and efficient there.
I am using mongo database with mongoose (ORM). I have a database that is working well with Express framework Application. Now I want to connect to this database with another Express Application.
Now here is the question,
should I make all mongoose models again in new project with Mongoose ? if not then what will be best option for this that we can use still use existing database mongoose.
I am assuming you are not serving the data via a REST API then. If you create a REST API for the mongoose models and then serve that data through URL's you won't have to create new models, rather you could just request the data via HTTP through GET, POST, DELETE, etc requests from the new express application.
If you want me to elaborate further, I can certainty do so.
I am trying out React-Starter-Kit for the first time and loving all the cutting edge features baked in (apollo/graphql-client in particular). A crucial part of any app for me is the database, and for that my understanding is the same author provides nodejs-api-starter which sets up a REST interface for accessing Postgres at localhost:5000 and has a graphql webui at localhost:5000/graphl.
That is about as far as I have been able to understand of the setup so far. I have changed the frontend code a little bit so a new Component "Counter" is loaded on the home page. I need to be able to make a new counter, fetch the latest counter, and increment decrement the counter. Write now the component just outputs the 'value' retrieved from the server at 5000.
I do not think I am accessing the 5000 server correctly, do I put the port in this url line somehow?
You can pull the repo down from : https://github.com/Falieson/react-starter-kit-crud-counter-demo
This is my first time setting up a nodejs api server, I am used to using MeteorJS which has pub/sub to MongoDB baked in. I am looking forward to the separation the RSK strategy (which seems more industry standard?) provides.
I've just done setting up the full site with Database from React-Stater-Kit, I'm also a newbie so I understand your frustration.
About this question, you don't need the NodeJS-API-Starter, it has enhanced function ( such as Redis cache ) and it's not suited for newbies. You should look deeper into the RSK, it already has the DB. If you ran the boilerplate and played around, change is you'll see file database.sqlite in your folder, it's the database. Here are the things you should learn:
Use SequelizeJS to connect the NodeJS server with database. Your database can be MySQL/MariaDB, PostgreSQL or SQLite. The connection is easy and there's tool to auto-generate Models from your database
How to create GraphQL's Types and Queries. If your queries need to search through the database, import Sequelize's models and use its functions.
Test your API via GraphQLi
Note: if you want to use MongoDB or other NoSQL, try Mongoose instead of Sequelize.
I am attempting to run node.js commands within my three.js project. Something as simple as declaring SQLite3 and initializing my database doesn't seem to be working. Ultimately I want to run UPDATE, INSERT, DELETE commands throughout game play as the user picks up items. Since node.js and three.js are both JavaScript packages, I assumed they would fit well together. There doesn't seem to be much information about this, so what I want to know is it possible to combine the two or am I wasting my time?
var sqlite3 = require('sqlite3').verbose();
var fs = require('fs');
var db = new sqlite3.Database('shopDB.db');
As discussed, you can't use node.js in the browser. If you want your browser app to talk to a database, you can expose a REST API around your database. This means exposing some HTTP endpoints to access your data.
For example, you might POST some JSON object describing some data from your browser-based app to http://someurl/some_path and your web server would be listening for a POST to the /some_path url, at which point it would read the POST data and insert a new entry into your database.
You could use jQuery's ajax() function to make requests to the API.
This blog post runs through an example REST API built around a sqlite database.