Unable to resolve module url from cloudinary - node.js

I am building a React Native app and tried to simply:
var cloudinary = require('cloudinary');
However, I keep getting an error:
Unable to resolve module url from node_modules/cloudinary/lib/config.js: Invalid directory /Users/node_modules/url
I have tried many of the suggestions for the Github thread on this including rebuilding the project, however, I still get the same error.
My gut is that this has something to do with the way lodash or other modules are being required. The same issue happened when I tried to require passport but not async.
What am I missing here? Any advice on what to look for when npm'ing files would be greatly appreciated.

Related

Node Crypto missing a lot of methods when running in browser

I have a nextjs app and I'm trying to use some of node crypto methods like hkdf, scrypt, generateKeyPairs... The problem is I get an error saying there's no such functions. I import crypto from 'crypto' then console.log(crypto) and I notice those functions were missing from the crypto object Image of this. I create a new javascript file, initialize node, does the same thing and all the functions are there. Image of this I'm really confused on why this happen... Please help.

Remove warning on Node.js WebStorm

I am learning backend with Node.js and using middleware to catch for errors and send a different response code and body.
The warning is similar to err.message.
How do I remove these warnings?
Are you using express? Its methods are generated dynamically in runtime, so they can't be resolved during static code analysis. Installing TypeScript stubs should help to get methods work: put cursor on 'express' in const express = require('express'); , hit Alt+Enter and choose Install TypeScript definitions for better type information to install typings - see https://www.jetbrains.com/help/webstorm/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files

How do I access node modules client-side when building an Express app?

I'm trying to use intl-tel-input in a project I'm building using express and ejs.
I have app.use(express.static(path.join(__dirname, 'public'))); in my app.js which means Express serves all static files from the public directory in my project.
I am unable to integrate intl-tel-input as it's a node module and the relevant css and js files are located in /node_modules/intl-tel-input/build/... and they are not served by Express at all. Thus, when I try to link to them in my Ejs template, I get a 404 error.
How do I solve this? All the ideas I have seem like the wrong approach.
After struggling with this for a while and exploring solutions like Webpack, RequireJS and other not so elegant ones, I found this answer to be the most relevant, easy and effective solution for this particular problem.

Error importing superagent in React code

I have a NodeJS server code written in JSX where I'm importing superagent like so:
import request from 'superagent';
When server starts after build, I get the following error:
TypeError: require is not a function. And this happens at the following line in my compiled code:
var crypto = require('crypto');
On tracing back I realized that crypto is required by 'formidable', which is required by 'superagent'.
I have the same superagent import in my client side javascript code but that works fine. I diffed the compile JS code for node(server), and client, and both are the same. So it doesn't seem like an issue with the way its build.
Has anyone seen this error before and would you know what needs to be done?
Found a solution to this here:
https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack
Adding the said plugin to web pack solved the issue.

Stuck on getting mongoose, node and express to play nice together

I am following along with a node.js and express tutorial at DailyJS and have already hit a wall.
In the tutorial it says to do this:
mongoose = require('mongoose').Mongoose
db = mongoose.connect('mongodb://localhost/nodepad')
but beforehand he was talking about the code inside the app.js file, so I assume he means for the above code to go inside app.js but I don't know. At this point I download the nodepad from github to see where he actually put the mongoose code, and I can't find the above code anywhere in the entire application!
So I am at a loss. Things are already confusing because a default skeleton site made by express is different in many ways to the tutorial, because express has changed a lot in the 2 years since the tutorial was written.
So i'm trying to follow along but I just get really stuck where he says write some code but gives no indication where this code is meant to go.
And afterwards the tutorial says to add a models.js file, and I wonder where this goes, inside the directory perhaps?
(I also understand the above code is outdated and the correct code can be found here, the problem is not the code but where in express its meant to be placed)
Please give me some guidance.
Thanks
Both of those go in app.js. I can give you some more details. I use mongoose and express all the time. I don't use var mongoose = require('mongoose').Mongoose All I use is var mongoose = require('mongoose')
Let me know if you need any further help.

Resources