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.
Related
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.
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)
i'm trying to make(i don't know what it's called, hot load? hot reload?) Meteor-like real-time loading of data, but by using node.js not Meteor.
and i'm using the ddp module for the client(=browser, i have not tried it yet) and ddp-reactive-server, well, for the server.
server.js is like this:
var DDPServer = require('ddp-server-reactive');
var server = new DDPServer();
var todoList = server.publish('todolist');
after that i run the server using the command node server.js --harmony_proxies(notice i'm already using the flag) this is what i get:
[aseds#localhost ~]$ node server.js --harmony_proxies
/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049
throw new Error("proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag");
^
Error: proxies not supported on this platform. On v8/node/iojs, make sure to pass the --harmony_proxies flag
at global.Proxy (/home/aseds/Desktop/projeh/css-goodness/node_modules/harmony-reflect/reflect.js:2049:13)
at publish (/home/aseds/Desktop/projeh/css-goodness/node_modules/ddp-server-reactive/lib.js:211:32)
at Object.<anonymous> (/home/aseds/Desktop/projeh/css-goodness/ddpserver.js:10:23)
at Module._compile (module.js:397:26)
at Object.Module._extensions..js (module.js:404:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:429:10)
at startup (node.js:139:18)
at node.js:999:3
my nodejs version v5.4.1.
i'm not even sure if that's actually possible to make the automatic reload feature of Meteor this way but i'm trying! :)
Thanks in advance for any help you are able to provide.
I came across this thread with regards to --harmony-proxies:
https://github.com/tvcutsem/harmony-reflect/issues/56
The relevant bit:
I released version 1.4.0 which, when loaded twice according to the script outlined above, loads correctly.
Note that loading v1.3.1 of this library followed by v1.4.0 will still fail (the other way around works fine). So it's important that your dependencies upgrade to the latest version.
It appears that if harmony-proxies is loaded as a node dependency twice, with different versions required, and a version before 1.4.0 is loaded first, then you will see this error.
Please, help me How can i solve this problem?
Starting static webserver: /home/ubuntu/node/node_modules/express/lib/express.js:89
throw new Error('Most middleware (like ' + name + ') is no longer bundle
^
Error: Most middleware (like cookieParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.
at Function.Object.defineProperty.get (/home/ubuntu/node/node_modules/express/lib/express.js:89:13)
at Object.<anonymous> (/home/ubuntu/node/static-app.js:26:16)
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)
at startup (node.js:124:16)
at node.js:811:3
You have updated your express to 4.0, but it doesn't have all the middleware included now, so you have to install them manually.
See the Moving to Express 4.0 guide
Express 4 no longer depends on Connect, and removes all the built-in middleware from its core, except express.static. This means Express is now an independent routing and middleware web framework, and Express versioning and releases are not affected by middleware updates.
With the built-in middleware gone, you must explicitly add all the middleware required to run your app. Simply follow these steps:
Install the module: npm install --save
In your app, require the module: require('module-name');
Use the module according to its documentation: app.use( ... );
I'm new to node.js world, I'm using node.js v0.8.4. I googled for this issue. Yes, i got solutions for this, but still could not understand as a beginner. So please help me......
i was going through a node.js tutorial. In that tutorial node.js v0.1.103 is used and he writes
require.paths.unshift(__dirname+'/vendor');
var http = require('http'),
sys = require('sys'),
nodeStatic = require('node-static/lib/node-static');
var server = http.createServer(function(request, response) {
var file = new nodeStatic.Server('./public', function() {
cache: false
});
request.addListener('end', function() {
file.server(request, response);
});
}).listen(8000);
And the script above works for him. When i write the sample script and run, i get this error.
C:\Documents and Settings\local>node C:\xampp\htdocs\rt\node\livestats\
server.js
Error: require.paths is removed. Use node_modules folders, or the NODE_PATH envi
ronment variable instead.
at Function.Module._compile.Object.defineProperty.get (module.js:386:11)
at Object.<anonymous> (C:\xampp\htdocs\rt\node\livestats\server.js:2:8)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
How do i make node to load files from custome directory and How to i solve this issue? My OS is windows
Thank you......
require.paths is deprecated a long time ago. The tutorial for node v0.1 is pretty much useless now, as nearly everything has changed since then.
If you installed node-static with npm install, you can just use require("node-static") without specifying the entire path (and, of course, without using require.paths).