couchapp dosen't work! (node.couchapp.js) - node.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.

Related

Deployement Nuxt.js ssr on passenger : SyntaxError: Cannot use import statement outside a module

I'm deploying my nuxt app on planethoster who use Passenger to run Node.js Application. I build the app by using ">npm run build" and deployed the content off .nuxt folder on the server, with "server.js" as entrypoint. but I ran on the following error:
/home/scalcmjx/test.scalomhouseplans.com/server.js:1
import Vue from 'vue'
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at Module.require (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:80:25)
at require (internal/modules/cjs/helpers.js:74:18)
at loadApplication (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:243:2)
at setupEnvironment (/opt/cpanel/ea-ruby27/root/usr/share/passenger/helper-scripts/node-loader.js:214:2)
Please Someone know how to manage it?
What is your node.js version? Try using the current LTS: 14.17.0
If I'm not mistaken, the import syntax is officially supported since v14, so this should maybe fix one issue.
Also, you need to deploy dist and not .nuxt, the latter is used for caching purposes.
I'm not sure of what is the process for this specific host, but you should probably get some decent ideas from the deployment section of the official documentation: https://nuxtjs.org/docs/2.x/deployment/deploying-to-21yunbox
There are a lot of hosting solutions there, one is probably looking like Planethoster.

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.

Expressjs change context where the server executes the app from

I'd like to know if it's possible to change the context from where the Express server is serving from, to avoid issues in the import/require files in the App that is served.
I'm serving from [root]/server.js, this file checks for the process.env.NODE_ENV and then requires a file in let's say ./dist/ENVIRONMENT/server.js
if (['staging', 'production'].indexOf(process.env.NODE_ENV) > -1) {
require('./dist/' + process.env.NODE_ENV + '/server.js')
} else {
require('babel-register')
require('./server.dev.js')
}
The files that are served are triggering an error related with the import/require locations that fails for the reason explained in the previous paragraph
Error: Cannot find module '../../../../xxxxx'
Why am I doing this? I'm transpiling the server source code for non development (that runs with babel) and then copied to the distribution directory. I understand that I can have tasks to rename and move this accordingly during deployment, that also solves the problem, but I'd like to learn or understand if we're able to change the context where the Express server, serves from!
From the top of my head, I guess I'll have to solve it through something like (which I'll be testing):
var dist = path.resolve(__dirname, '../../')
app.use(express.static(dist))
Which I attempted, but failed, same error:
Error: Cannot find module '../../../../config'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/xxxx/www/projectFoobar/dist/staging/lib/services/foobarService/index.js:13:15)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
The config file happens to be in the [root] directory.
** OK just realised that using import/export is a bad practice
https://nodesource.com/blog/es-modules-and-node-js-hard-choices/

Unable to push couchapp with node.couchapp.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.

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());

Resources