Firefox console access required module in ionic2 - requirejs

I have a very simple Ionic2 project with some providers that import pouchdb library.
import * as PouchDB from 'pouchdb';
I want to access pouchdb from the console somehow. How can I get that working?

I want to access pouchdb from the console somehow.
Assuming that you installed the pouchdb dependency by running
npm install pouchdb --save
And then (optional but recommended) installed typings as well
npm install -g typings
typings install --global --save dt~pouchdb dt~pouchdb-adapter-websql dt~pouchdb-browser dt~pouchdb-core dt~pouchdb-http dt~pouchdb-mapreduce dt~pouchdb-node dt~pouchdb-replication
Just like you said, you need to import it in your code
import * as PouchDB from 'pouchdb';
And then use the new PouchDB('aName') method to get an instance of the db. Then you can just use that instance in the console.
#Injectable()
export class MyDbClass {
db: any;
constructor() {
this.initializeDb();
}
initializeDb(){
this.db = new PouchDB('aName');
console.log(this.db);
}

Related

Custom NPM package - Exposing Internal Interfaces to custom npm package

I have some npm packages that are used internally in company projects, and I would like to expose some of the interfaces used by dependencies from this component.
So if I have a project for a npm package (called company-utils) that has a dependency with axios, and I want to expose a method that creates an instance for axios, how can I export it so other projects that installs this company-utils can see the axios interfaces/methods/etc ?
It seems to me that you are using this company-utils as a wrapper for axios? If you want to export something you can put an index.js at the root of the package and export it there. Then it will be exposed to anyone who installs the package.
so the structure will be:
package
src/
index.js
package.json
Then inside index.js
import method from 'src/<path to method file>'
export method
If you install the package into another project that method will be exposed
import method from 'package'

hapi.js Version 18.x Typings

I recently upgraded my project to use the #hapi/hapi node modules vs. the old hapi module. I'm using version 18.3.1 ("#hapi/hapi": "^18.3.1").
My Typescript definitions no longer work as the Import reads: import * as Hapi from 'hapi';
When running the node process I get the module not found error. Is there a way to point the #types/hapi typings to the new #hapi/hapi module?
Uninstall the #types/hapi dependency. This didn't work for me moving to 18.3.1. Instead install #types/hapi__hapi. I searched for a while and ran across that package, which seems to do the trick.
npm un #types/hapi -D
npm i #types/hapi__hapi -D
Then instead of importing from 'hapi', import from '#hapi/hapi'.
import * as Hapi from '#hapi/hapi';

Module 'express' is not listed as dependency in package.json

I am getting Module 'express' is not listed as dependency in package.json when executing firebase deploy in the terminal.
When tapping on the link next to it it takes me to this part of my code:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { response } from 'express';//here
admin.initializeApp()
I have looked around and could not fined an answer to my question.
How do I fix this?
Per comments on the original post:
Typing npm i express --save should add express to the dependencies section of your project's package.json file Even if you already have it installed. For example:
{
...
"dependencies": {
.
.
.
"express": "^4.16.4",
},
}
More specifically for firebase cloud functions, the functions folder has it's own package.json file. You need to run npm i express --save from within the functions folde
You need to npm install --save express inside ./functions and be careful not to do it in the root directory.
Additionally, if you are using TypeScript, you need install the type definitions: npm install --save #types/express.

Importing nodejs `fs` with typescript when executing with ts-node?

I'm trying to run the following code with ts-node.
import { writeFileSync, readFileSync } from 'fs';
However I get:
src/main/ts/create.ts (1,45): Cannot find module 'fs'. (2307)
What do I need to do in to allow typescript to import the fs module?
You need to run:
$ npm install #types/node --save-dev
If you need additional information you can refer to the NodeJS QuickStart in the TypeScript Deep Dive by Basarat.

Ember-cli import node package into test

I need to include jwt-simple into a test so that I can generate JWT tokens and validate the UI does what it needs to do given certain scenarios.
I have tried npm install jwt-simple and then import jwt from 'jwt-simple/jwt'; and import jwt from 'jwt-simple'; but neither work.
Should I be able to import node packages into the tests like this?
As jwt-simple is not an ember addon, you cannot import the module like this in an ember-cli setup. To import an npm module which is not an ember addon, you will need ember-browserify. So install ember-browserify first:
npm install --save-dev ember-browserify
Then import the module as follows:
import jwt from 'npm:jwt-simple';

Resources