Node.js error: Cannot find module 'firebase/storage' - node.js

I've been using Firebase Cloud Storage for my app, and so I required 'firebase/storage' in my server.js file, as shown below. The code was working fine last night, but when I tried "node server.js" this morning, I keep getting the module error:
Error: Cannot find module 'firebase/storage'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ubuntu/workspace/app.js:10:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
Here is a snippet of the server.js code:
var express = require('express');
var logger = require('morgan')
var bodyParser = require('body-parser')
var app = express();
var path = require('path');
var formidable = require('formidable');
var fs = require('fs');
var admin = require('firebase-admin')
var storage = require('firebase/storage')
I've initialized in the fireabase app and made correct references to the firebase storage in my html and js, or else my code would not have worked last night. Why am I getting this error now?

You should use this lib to use storage.
npm install firebase
https://firebase.google.com/docs/storage/web/start

Related

node.js module not found in subfolder

I am building a basic web scraper using node, express, and puppeteer, and when I try to run node index.js. I get this error
alexskreen#Alexs-MacBook-Air WOD-Scraper2 % node server/index.js
internal/modules/cjs/loader.js:960
throw err;
^
Error: Cannot find module './server/scrapers'
Require stack:
- /Users/alexskreen/Desktop/WOD-Scraper2/server/index.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15)
at Function.Module._load (internal/modules/cjs/loader.js:840:27)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/Users/alexskreen/Desktop/WOD-Scraper2/server/index.js:8:18)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/alexskreen/Desktop/WOD-Scraper2/server/index.js' ]
}
Before adding my require statements everything is working:
const express = require("express");
const app = express();
const port = 3000;
const bodyParser = require("body-parser");
const scrapers = require('./server/scrapers');
const db = require('./server/db');
If module is in your subfolder you should use,
const something = require("./subfolder/module");
If it is not a subfolder module then make sure it is installed in node_modules.

ActiveDirectory Authentication using NODE for Windows SQL 2012

Am using node Active directory for validating users. Here is my node code:
const express = require('express');
const async = require('async');
const activedirectory = require('activedirectory');
var underscore = require('underscore');
const ldap = require('ldapjs');
const bunyan = require('bunyan');
const app = express();
app.get('/',(req,res) => {
var config = { url: 'ldap://10.100.1.10',
baseDN: 'dc=HBCAudit,dc=COM',
username: 'traveldesk.dev',
password: '$oftvision#123' }
var ad = new activedirectory(config);
});
//Port Number
const port = 7000;
//CORS Middleware
app.use(cors());
//Start Server
app.listen(port, () =>{
console.log('Server started on port '+ port);
});
But am getting error in command prompt like this:
c:\spitravel>node app.js
module.js:471
throw err;
^
Error: Cannot find module 'once'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (c:\spitravel\node_modules\ldapjs\lib\client\client.js
:8:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
I don't know why am getting this error. Am new to NODEJS.
Its due to depencies of ldapjs module, please run npm install ldapjs and recheck

Cannot node app.js because 'Cannot read property 'MemoryStore' of undefined'

I'm using vagrant and virtualbox with precise32 for my setup. Installed Node.js v0.10 using:
curl -sL https://deb.nodesource.com/setup_0.10 | sudo bash -
sudo apt-get install -y nodejs
and i can't seem to sudo node the following:
var everyauth = require('everyauth');
var nconf = require('nconf');
var Recaptcha = require('recaptcha').Recaptcha;
var crypto = require('crypto');
var connect = require('connect');
var cookie = require('cookie');
var express = require('express');
var models = require('./models/');
var hash = require('./hash');
var config = require('./config');
/* load API keys */
nconf.env().file({file: 'settings.json'});
var session_store = new connect.session.MemoryStore();
I got the following error:
TypeError: Cannot read property 'MemoryStore' of undefined
at Object.<anonymous> (/vagrant/app/auth.js:16:40)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/vagrant/app/app.js:8:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
at node.js:945:3
I have to say that 3 years ago when I made the project, I simply did 'sudo npm install' and the tried to run and everythin was fine. I am thinking there is a incompatibility issue between js and the newly installed npm.
Change
var connect = require('connect');
...
var session_store = new connect.session.MemoryStore();
to
let app = express();
let session = require('express-session');
app.use(session({ ... });
Or install old version (2.x, 3.x) of Express

How avoid Error: Cannot find module ‘express’ [duplicate]

This question already has answers here:
can not find module express --on windows
(2 answers)
Closed 7 years ago.
First I installed express in this way: nmp install -g express
I check my Path variable and it is set "C:\Users\Eventi\AppData\Roaming\npm".
This is the code:
var http = require('http');
var fs=require('fs');
var express = require('express');
var app = express();
and this is the error:
Error: Cannot find module 'express'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\Eventi\Desktop\Node.js\Progetti\ProveNodeJS\NodeJSProve\HelloWord.js:7:15)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Anyone can help me?
You have to "require" it in your application. Write var express = require('express'); then initialize express with var app = express();

Twitter API request error while using node.js

I am trying to make a request to the Twitter API and respond with the JSON.
This is my code.
var http = require('http');
var request = require('request');
var url = require('url');
app.get('/twwets/:username', function(req, response) {
var username = req.params.username;
options = {
protocol: "http:",
host: 'api.twitter.com',
pathname: '/1/statuses/user_timeline.json',
query: { screen_name: username, count: 10}
}
var twitterUrl = url.format(options);
request(twitterUrl).pipe(response);
}).listen(8080);
And this is what I get when I run node app.js in my terminal:
module.js:340
throw err;
^
Error: Cannot find module 'require'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/geosh/node.js_practice/express_practice/app.js:2:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
I need to know what do I do wrong.
[My code may seem useless, but it's just for educational purposes. Please excuse any mistake.]
EDIT: I still get the same error after I saved and run the code in my shell.
Typo;
var request = require('require');
should most likely be
var request = require('request');
EDIT: You're also missing express, I suspect you'll want to add these lines;
var express = require('express');
var app = express();
...and npm install request express to get the modules installed.
Refer the following links may use
http://expressjs.com/
For Twitter Authentication
http://passportjs.org/

Resources