I have created a file in my database using gridFs.The is as follows:
storeAudio.js
var mongoose = require('mongoose');
var fs = require('fs');
var Grid = require('gridfs-stream');
Grid.mongo=mongoose.mongo;
//establish mongoDB connection
mongoose.Promise = global.Promise;
var conn = mongoose.createConnection('mongodb://localhost:27017/aHolyBoly');
conn.once('open',function(){
var gfs = Grid(conn.db);
// var db = new mongo.Db('aHolyBoly', new mongo.Server("127.0.0.1", 27017));
//var gfs = Grid(db, mongo);
var writeStream = gfs.createWriteStream({
filename:'song1.mp3'
});
fs.createReadStream('../list/hero.mp3').pipe(writeStream);
writeStream.on('close',function(file){
console.log(file.filename +'Written to db');
});
});
Now I want to make an API using express and node so that I can connect my Backend with Frontend using Ionic2 and Angular2.So I saw this tutorial: https://www.joshmorony.com/building-a-review-app-with-ionic-2-mongodb-node/ Now in this tutorial, Http verbs get, post etc are used to make the api calls and then it is used as a provider.So is this the way to continue with my project?And if this is the way then I have some questions which are below:
In the link mentioned above there is server.js file.In that file a code as mongoose.connect('mongodb://localhost/reviewking');
Why this is used again if already used in my file storeAudio.js?
Secondly, The http verbs should be used in the similar fashion using gridFs?
Note:I am using first time everything (except ionic2 and angular2).Please let me know if any more inputs shoud be provided.And Sorry for the mistakes if found in this post.
via Aditya Jain
No comments:
Post a Comment