Home Doc Storing pdf in database using nodejs and mongo

Storing pdf in database using nodejs and mongo

Sometimes you just need a quick API. I was working on a project storing pdf in database using nodejs and mongo and needed just that.

I needed an API, and I didn’t want to spend a lot of time on it. Entity Framework model, and serve it using OData. My last one was even easier. JSON file and turns it into an API. A few minutes composing a JSON file if you don’t have one already and then a few lines of code to turn it into an API. Now I spend a few minutes writing a JSON file and 20 seconds opening a port and I have myself an API that I can share with the world.

Let’s say I want to write an app for dog walkers. Now let’s turn that into an API stat! I’m going to be thorough with my instructions in case you are new to things like this. I’ll assume you have Node. Finally, launch that project in your IDE of choice. Let me describe what’s going on in those few lines of code.

This is where your data goes. But I discovered that if you use this method, then the data is simply kept in memory and changes are not persisted to a file. If you specify a JSON file, then that file is actually updated with changes and persisted for subsequent runs of the process. So that’s pretty much all there is to it.

API is running on 1337. Then you can use CURL or Postman or simply your browser to start requesting data with REST calls. Now you have a new API running on localhost, but what if you want to tell the world about it. Or what if you are working on a project with a few developer friends and you want them to have access.

I usually use the latter just because it’s free and easy. You set your API up in about 4 minutes and your UI dev probably hasn’t gotten XCode running yet. Node trick I learned sometime ago and remember getting pretty excited about. First, let’s define the problem. If you are working on a Node project and you want to include an npm package as a dependency, you just install it, require it, and then do a fist pump.