Parse-Server Local Installation — external modules - node.js

I installed with success a Parse-Server on my local machine from this GUID.
I tried first with global installation, then I tried to understand better (It's the first time I see something related to Node.js) and I installed in a local directory. I think it should be the same.
this is what I done:
npm install parse-server parse-dashboard underscore
this is how the directory looks like:
/parse: ls
dashboard-config.json
logs
node_modules
ls node_modules/underscore
LICENSE
README.md
package.json
underscore-min.js
underscore-min.map
underscore.js
ls node_modules/parse
parse/
parse-dashboard/
parse-json/
parse-server/
parseurl/
Next I try to include also the cloud code I developed. the main.js has this content:
//var Image = require("parse-image");
var _ = require('underscore');
...
This is how I started the server:
node_modules/parse-server/bin/parse-server \
--appId APPID --masterKey MASTERKEY \
--databaseURI mongodb://localhost:27017/MyAPP \
--cloud /absolutepathfor/MyApp/cloud/main.js
and the error I got
module.js:341
throw err;
^
Error: Cannot find module 'underscore'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/......./main.js:2:9)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
How can I include in this case underscore, but in any case other libraries?
[update]
I installed globally the underscore lib (node install -g underscore).
I create a symbolic link cloud -> < path where is located cloud/main.js >
Next I created package.json with npm init command
I launch again npm install
I created app.js like described in the guid and I configured it using the same parameters above.
I started the server with node app.js
all gone fine. the problem right now is in permissions on create a new document, where I should already have that grants, but this will be another problem to solve. I hope this can help somebody else

I hit the same problem and error message. I did the followings and it works
npm install underscore
use this path:
var _ = require('../node_modules/underscore/underscore.js')
Refer to more details in this post.
Can't get 'underscore' to work with parse server

I just sorted a similar issue while transferring Parse.com CloudCode to a self hosted Parse Server on Nodejs; in one of the controller we had the line
var _ = require('underscore.js');
It had to be done like this on Parse.com. But now as we are on NodeJS and have NPM—it's enough to just do:
var _ = require('underscore');
(ie: drop the .js extension)

Related

How to accept Payments with Stripe

So this is my first time using Stripe to integrate payments for a website. What I am trying to do is add Stripe to my terminal for it to work correctly but I am getting an error. I have created a "Server" folder along with a "Server.js" file and when I try to initialize a new project it throws me an error.
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Royces-MacBook-Air:Kingdom Website roycewilliams$ $ cd server/
bash: $: command not found
Royces-MacBook-Air:Kingdom Website roycewilliams$ cd server/
Royces-MacBook-Air:server roycewilliams$ npm init -y
node:internal/modules/cjs/loader:926
throw err;
^
Error: Cannot find module './lib/_stream_readable.js'
Require stack:
- /usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-stream.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-group.js
- /usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/index.js
- /usr/local/lib/node_modules/npm/node_modules/npmlog/log.js
- /usr/local/lib/node_modules/npm/lib/cli.js
- /usr/local/lib/node_modules/npm/bin/npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)
at Function.Module._load (node:internal/modules/cjs/loader:768:27)
at Module.require (node:internal/modules/cjs/loader:995:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js:12:30)
at Module._compile (node:internal/modules/cjs/loader:1091:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1120:10)
at Module.load (node:internal/modules/cjs/loader:971:32)
at Function.Module._load (node:internal/modules/cjs/loader:812:14)
at Module.require (node:internal/modules/cjs/loader:995:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/local/lib/node_modules/npm/node_modules/readable-stream/readable.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-stream.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/tracker-group.js',
'/usr/local/lib/node_modules/npm/node_modules/are-we-there-yet/index.js',
'/usr/local/lib/node_modules/npm/node_modules/npmlog/log.js',
'/usr/local/lib/node_modules/npm/lib/cli.js',
'/usr/local/lib/node_modules/npm/bin/npm-cli.js'
]
}
Royces-MacBook-Air:server royce
williams$
You probably just need to get the dependencies from npm. Type npm i in the same directory of the project to get the dependencies. If you don’t have npm installed you need to install it first.
Did you create this folder by yourself or did you clone/download it from one of Stripe's examples/repos?
If you downloaded it from somewhere, can you share the link?
Edit: The quickstart guide also has steps that you can follow to setup your integration

Socket.io Syntax not Recognized on Server

Node server not able to understand socket.io syntax, even with all packages installed.
When I run my server locally with nodejs server.js it works fine is working. But, when I try to run it on my Ubuntu server, it does not seem to understand this line:
socket.on( 'client-data', ( serverpackage ) => {
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
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:902:3
The directory on my Ubuntu server is user/server, which contains all my server modules. Socket.io is installed, and I even checked to make sure all dependencies for socket.io are there too.
NodeJS-Socket-server-with-DB#1.0.0 /home/<user>/server
└── socket.io#2.1.1
I am also running this version of nodejs:
<user>#host*****:~/server$ nodejs -v
v0.10.25
You can't use arrow functions. You need at minimum version 4 of node however version 6 offers full compatability with arrow functions.
To fix your issue simply update node or change to a regular function like:
socket.on( 'client-data', function (serverpackage) {
Your nodejs version don't understand arrow function, check update if you want use it.
If not, please change arrow function to normal function.
Check Node.js ES2015 Support.

slimerjs Can not resolve required module encoding

I have seen slimerjs Can not resolve required module, works with phantomjs, but that one explains absolutely nothing, so I'll dare ask the question again.
I have done this:
$ npm install -g encoding
encoding#0.1.12 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/encoding
└── iconv-lite#0.4.13
So, apparently, it should be there?
Now, I'm trying this test script, as stated in https://www.npmjs.com/package/encoding - let's call it test_modload.js:
var encoding = require('encoding');
... and I try to run it with node:
$ node test_modload.js
module.js:338
throw err;
^
Error: Cannot find module 'encoding'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/path/to/test/test_modload.js:1:78)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
Apparently, here I have to use NODE_PATH:
NODE_PATH=/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules node test_modload.js
... and this command passes fine (i.e. returns nothing, and prints no errors).
But what if we try this with casperjs? The script becomes:
var encoding = require('encoding');
var casper = require('casper').create();
casper.run();
... and if I run with:
/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs test_modload.js
... again all is fine (i.e. returns nothing, and prints no errors).
But let's try this with casperjs with slimerjs engine:
$ SLIMERJSLAUNCHER=/usr/bin/firefox46 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs --engine=slimerjs test_modload.js
Script Error: Module: Can not resolve "encoding" module required by main located at file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js
Stack:
-> file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js: 350
Eh... I guess NODE_PATH is missing?
$ NODE_PATH=/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules SLIMERJSLAUNCHER=/usr/bin/firefox46 /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/casperjs --engine=slimerjs test_modload.js
Script Error: Module: Can not resolve "encoding" module required by main located at file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js
Stack:
-> file:///home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/casperjs/bin/bootstrap.js: 350
Damn it, I ran out of options. What do I do now, how can I get encoding to work with slimerjs? Note that the slimerjs docs state in https://docs.slimerjs.org/current/api/require.html that one should use require.paths, however, for node standalone, it would complain with:
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
... while slimerjs doesn't output this error; but still, no change if I do require.paths.push('/home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules'); - it still 'can not resolve "encoding" module'.
Just to make sure I have the right path, here is a listing:
$ ls /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules
casperjs encoding npm utf8 zombie
$ ls /home/USERNAME/.nvm/versions/node/v4.0.0/lib/node_modules/encoding/
lib LICENSE node_modules package.json README.md test
... so apparently the module is there.
So, how on earth can I get slimerjs to find and use the encoding module in a script?

Node.js NPM config error - " Error: Cannot find module './config/mail' "

Im following a book called "Building Node Applications with Mongo and Backbone". What im creating is a small social network site. Ive followed the steps through but am getting an error with npm config (I think)
when i run the app.js file it comes up with this error
> Error: Cannot find module './config/mail'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
this is the relevant code its referring to.
// Import the data layer
var config = {
mail: require('./config/mail')
};
Any suggestions on how to fix this? Thanks.
Try to install module with npm as admin in console: sudo npm install

NODE_PATH is being ignored or not working

I'm trying to run my node app on a new server and am having some issues with the NODE_PATH environment variable. The app works fine on my local machine (OSX Lion) but not on the server (Redhat linux). When starting my app with node app.js from within my project directory /development/nodeproject, I get the following error :
Error: Cannot find module 'mod/core/models/Category'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at /development/nodeproject/app.js:57:5
at Object.<anonymous> (/development/nodeproject/app.js:258:1)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
mod/core/models/Category is the first require() in my app.js and looks like this: var Category = require('mod/core/models/Category'). So apparently node is not looking for modules in my project directory.
I'm not sure why though, because I made the following changes (that are working just fine on my local machine).
added export NODE_PATH=/development/nodeproject to my ~/.bash_profile
ran source ~/.bash_profile
if I run env I see NODE_PATH=/development/nodeproject listed there
in my app.js if I console log process.env.NODE_PATH I get /development/framework (should this output an array instead of a string?)
Other information that might be relevant:
I'm on node v0.6.7
I'm doing all of this as root (sudo su -)
At this point I'm not sure what else I can do. Any help would be greatly appreciated.
NODE_PATH used for modules, not for solutions files.
Try
module.paths.push("/development/nodeproject", "one/more/path");
before any require() call. And you really should use a relative require like require('./mod/core/models/Category') for files in your nodeproject directory
The functionality you are looking for was removed. Use the node_modules directory or a relative require like require('./mod/core/models/Category').
This answer has more info: NODE_PATH error with node.js while attempting to setup jsctags for vim

Resources