Unable to push couchapp with node.couchapp.js - node.js

I'm trying to push a simple couchapp on windows, but I'm dooing sth. wrong.
First I'm installing couchapp using npm:
D:\test>npm -g install couchapp
D:\test>npm install couchapp
I know that there are two diffrent couchapps, but I'm shurely using the node couchapp:
D:\test>couchapp
The "sys" module is now called "util". It should have a similar interface.
couchapp -- utility for creating couchapps
Usage:
couchapp <command> app.js http://localhost:5984/dbname
Commands:
push : Push app once to server.
sync : Push app then watch local files for changes.
boiler : Create a boiler project.
Now I create a couchapp:
couchapp boiler
This creates a app.js and a attachments folder containing a simple couchapp. Now i want to push it to the couchdb:
couchapp push app.js http://localhost:5984/test
This results in the following error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'app.js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (D:\test\node_modules\couchapp\bin.js:78:24)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
What am I dooing wrong? Please help me

I don't know the answer to this but I can maybe help you debug the problem. If you go to this line and console.log the result of path.join(process.cwd(), path.normalize(pathname)) then you can find out where couchapp is trying to grab your app.js file.
Also if possible you should check out kanso.js. Last time I created a couchapp (six months ago) kanso.js was a lot better than node.couchapp.js.

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

Parse-Server Local Installation — external modules

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)

Dynamically generate Express routes fails in production environment

I've seen a lot of folks dynaimcally generating all their routes in the thier routes/index.js like so:
require("fs").readdirSync("./routes", 'utf8').forEach(function(file) {
if (file != 'index.js' && file != '.DS_Store') {
require("./"+file);
}
});
This works fine in development but not in production. If I remove this and add the routes manually it works fine. Any Ideas?
Here's my error if you think that would help:
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
Error: ENOENT, No such file or directory './routes'
at Object.readdirSync (fs.js:376:18)
at Object.<anonymous> (/app/routes/index.js:4:15)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object.<anonymous> (/app/server.js:50:14)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
Process died with exit code 1. Restarting...
As Mark Bessey says in his answer, you are resolving the routes directory from your current directory -- not relative to where your main script lives. You should probably use __dirname. From the docs:
The name of the directory that the currently executing script resides in.
fs.readdirSync(path.join(__dirname, "routes"))
Also, you don't need to pass 'utf8'. Also, be very careful using any Sync functions in your code -- generally, it's ok in the top level scope, before the server starts accepting requests, so it should be ok in this case.
It seems likely that in production, the current directory is not getting set to the parent of your "routes" directory. How are you launching your app in production? What output do you get from
console.log(process.cwd());

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

couchapp dosen't work! (node.couchapp.js)

I have a problem: couchapp has been installed by me, but it works not too well.
I try to repeat shown here: http://vimeo.com/26147136 but:
master#master:~/WebDev/superblog$ couchapp push app.js http://localhost:5984/superblog
The "sys" module is now called "util". It should have a similar interface.
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: require.paths is removed. Use node_modules folders, or the
NODE_PATH environment variable instead.
at Function. (module.js:376:11)
at Object. (/home/master/.node_libraries/couchapp#9999.0.0-LINK-b6f5885b/index.js:4:21)
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)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object. (/home/master/WebDev/superblog/app.js:1:79)
at Module._compile (module.js:432:26)
I don't know as it to correct. Help me, please!
You can also use Kanso to push apps written to the node.couchapp.js API: http://kan.so/docs/Kanso_for_node.couchapp.js_and_reupholster_developers
This does not help you directly, but you can use Reupholster until node.couchapp.js runs for you.
http://reupholster.iriscouch.com/reupholster/_design/app/index.html
(Disclaimer: it is my project)
The format of the project is pretty much the same as node.couchapp.js, so you can get your couchapp development going, and switch back to the node version at any point. Reupholster is just a little easier to get running.
Hope that helps.

Resources