In [2]:
!npm install mongodb --save
Check on this friendly warning.
npm WARN enoent ENOENT: no such file or directory, open '/home/dmmmd/Dropbox/Wyncode-Academy/web-presence/zipped-code/content/posts/python-mongodb/grilled_flpd_data/package.json'
In [2]:
!ls -als
I forgot npm init. That is why I have no package.json file.
In [ ]:
!npm init
I have to run npm init inside of a terminal and not a Jupyter notebook. Some Jupyter notebooks don't do stdin it seems. NB: I am working in a Jupyter notebook with a NodeJS kernel.
And now a package.json file exists.
In [4]:
!cat package.json
Add code to connect to the server and the database 'app'
In [5]:
const MongoClient = require('mongodb').MongoClient,
assert = require('assert');
// Connection URL
const url = 'mongodb://localhost:27017/app';
// Use connect method to connect to the server
MongoClient.connect(url, function(err, db){
assert.equal(null, err);
console.log("Connected successfully to server.");
db.close()
});
So far so good!
I followed the instructions in the blog and now Vim lints *.js files as expected!
Setting up Vim for React.js https://t.co/vAsA7SPTuy via .@jaxbot Thank you for a simple solution to my Vim linting situation.
— Don Morehouse (@dmmfll) September 16, 2016
In [6]:
!tree local_db
In [7]:
!cat local_db/index.js
Trying out the new package
In [1]:
const testDatabase = require('./local_db');
console.log(testDatabase());
Success! A simple module was created and imported and run.