Using p5.js, node.js and mongodb for a complete website - node.js

I want to create a small mini-mart website using all the javascript codes, p5.js for frontend, node.js for backend and mongodb for the database.
Is it good to work with all the javascript codes?
if not, what are other js to work on?

You can definitely do it, although P5 is not that great for frontend... Node.js is good, but unless you just want to build an HTTP server from scratch with the default node.js API you should use something like Express. Also, you should use something like Mongoose for interaction with the Mongo database, since it usually makes everything much easier!

Related

I am trying to connect Angular to MongoDB

I have a simple Angular app and it is running in Local Host 4200. How do I save the form values and store them in a MongoDB database?
Angular is a web framework dedicated for the client-side, MongoDB is
a NoSQL database, to save your data put into your angular app to your
Database, you need a server-side implementation like nodejs or
python, java, etc ..
I recommend for you to use expressjs as an API framework it can helps you to get started
Angular is not supposed to connect directly to a DB in an real project, so there is not much of a point to practice doing so. You should have an server-side application or a mock to do so. If you are trying to build a front for studies you can use packages such as this one to begin: https://www.npmjs.com/package/auto-api
It is of simple use and you can save data without configuring or installing a DB.

How to build a UI with typescript/NodeJS

I'm absolute new to this topic. I want to learn Typescript using NodeJS and have some simple questions. NodeJS is working with Javascript, as far as I know, but how do you get an UI? Do you have to create a HTML/CSS Webpage and run it with Typescript? How do you get Images, Options, Buttons in Typescript? How are they implemented in the Code? I found a lot of Tutorials, but they just return "Hello World" and I don't think I have to "write" the whole page in an output in Typescript.
NodeJS is pure server side javascript, you wont build the UI with it, you would serve the html/css/js to the client, and maybe create an API to communicate with the client.
I assume you dont need an example how to create a Node project, as you stated to have read some tutorials about it.
For starters, i would advise to go for NodeJS plus Expressjs on the server, then maybe start to serve simple static websites (like a handwritten 'index.html'). Expressjs makes development especially in the beginning a lot easier. Serving static files would just need something like
app.use(express.static('public'))
..in your server code. If you navigate then to e.g. localhost:3000/test/route, it would look for the /test/route/index.html in your public folder (which should be in your project root)
Then use a framework for client side development.
If you want to use Typescript for the development of the client side of the app, you might want to look into Angular. It is pretty tightly bound to Typescript, but the learning curve is pretty harsh if you are a beginner with this. Other client side frameworks that work well with Typecsript pretty much out-of-the-box or via cli are Vue.js and React, just as examples.

Connect to MongoDB remote server with Ionic

I'm trying to develop an application in phonegap/ionic and I want to use a remote database to store my data. I want to use MongoDB.
I already tried lots of ways such as this quick start guide.
By using this I can connect to DB but this is pure node.js and the require() function cannot be recognized when I try to add this code to an ionic starter app. Maybe require is not supported in ionic
Is there a way that can achieve it in Ionic?
Please let me know if you want some more information.
The thing is; you can't connect Ionic to MongoDB directly. No, there's not workaround, no magic involved, it's just not the way this is supposed to work. Ionic works on top of Angular and Angular is a frontend framework.
However, the way you should do it is that you basically create a (RESTful) API on your server side.
Most likely this will be made with Node.js which will talk directly to MongoDB and query it. A framework very well suited for this (you actually may be using it already) is Express.
After you write your (RESTful) API then you can consume it through your services in Angular by using Angular's $resource object.
Sure, this is not a step by step answer, and it seems you're just starting in this area, so you have some learning do to on your part (REST, RESTful, $resource, services...), but I wish you good luck and if you'll have any more specific questions, don't hesitate to ask them.

Is there a way to self-host mongoose databases?

I am getting started with writing an API for a project and the tutorial I am following suggests I sign up for a hosted solution. I think that is ridiculous. My project is simple and I do not feel the need to be locked in to a service. If it helps, I am using Express.
Mongoose is a node.js module (library) which is used to interact with a database, called MongoDB.
There are some websites like mongolab.com which offer plans for development for free, so you would jsut need to sign up and you will get a database without installink anything in your computer/server etc. This is why they say it is easier.
You can install MongoDB in your local computer to test (I think most of us have it) and use just that one for developing and testing.
To install MongoDB it all depends which Operating System you are using at the moment. But you can look up on google: "Install MongoDB MacOSX/Window/Ubuntu/etc.." and normally is just one simple command. To connect to it in your local you don't need a user or anything I guess.

How can I properly structure my NodeJS, Express, and MongoDB code?

I am new to all three but I do know javascript well. I understand basics of them all but do not understand what the best way to implement the NodeJS server javascript with the express MVC and MongoDB database querys. I want to break up all this into their own files obviously but I am not sure how everything fits into the pre-created project template created by Express. Does anyone have a good solution or resource to share with me? Thank you
I recently started with node.js, express and mongodb myself and it's true the resources out there are mostly outdated. First of all, express is not an mvc framework. It has no opinion on the structure which you'll find out that it makes it so great. Your question is how to organise the code? It's clearly a personal preference but you can create a model folder where you can put your db queries for specific resources, your lib folder where you can establish a connection to your mongodb instance and call it wherever you need it and use the routes folder for your more specific needs like controllers on a traditional MVC. Another thing is that you have to decide how to interact with mongo. You can either use the native mongodb driver, perhaps with mongoskin as suggested, or mongoose for easier interactions such as defining schemas. Personally i prefer the native but it took me a while to get what it does and how it works. Finally for resources what i can suggest from personal experience and it's still my own opinion, is that the best thing you can do is buy the book Node.js in Action which was what made me realize what node.js is all about and how to use it. Hope it helps...

Resources