node.js - When trying to execute an JavaScript file gives me an: SyntaxError: unexpected token ) -
during path on creating chat application, trying create app.js file till came across easy/novice silly syntaxerror don't think wrong it, still causes issues me progress onwards, tried adding additional parentheses, brackets or semicolons. wouldn't resolve :/
this app.js file:
var express = require('expres'), //now in express no longer create http server automatically //app variable function bundles in express //for socket.io need http server object so, need create manually app = express(), //create variable called "server". //requires http module, "createserver" (creates server) , pass data onto "app" variable. server = require('http').createserver(app), //then need create socket functionality. //create variable called "io". //the variable "io" requires "socket.io" , need make "listen". //so why need http server, parameter of "listen". //socket.io listens http server object. //so need pass "server" io = require('socket.io').listen(server); //next: need tell server on port listen on. //pick available port, in case "3000" within option below. server.listen(3000); //after setting server //we need create "route". //right can't access pages. //and express makes somethings easier. //makes routing bit easier. //we going use variable "app" . "get" function variable equals "express framework". //then set root directory "/" forward slash sign. //so that's first parameter on client trying access. //and without express have "function" "http request" , "http response" parameters. app.get('/'), function(req, res){ //and declare "http response" , . "sendfile" because, going create file called "index.html" want client whenever goes "localhost:3000". //then create "directory name" + "index.html" web page. res.sendfile(__dirname + '/index.html'); }); //then check if works within command prompt execute command: "node app.js" //which run javascript file.
and here result when input node app.js
command! i've installed socket.io executing command npm install socket.io
still wouldn't solve issue. :/
c:\chatapplication>npm install socket.io npm http https://registry.npmjs.org/socket.io/1.4.8 npm http 304 https://registry.npmjs.org/socket.io/1.4.8 unbuild socket.io@1.4.8 npm http https://registry.npmjs.org/engine.io/1.6.11 npm http https://registry.npmjs.org/socket.io-adapter/0.4.0 npm http https://registry.npmjs.org/socket.io-parser/2.2.6 npm http https://registry.npmjs.org/has-binary/0.1.7 npm http https://registry.npmjs.org/debug/2.2.0 npm http https://registry.npmjs.org/socket.io-client/1.4.8 npm http 304 https://registry.npmjs.org/socket.io-parser/2.2.6 npm http https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.6.tgz npm http 304 https://registry.npmjs.org/engine.io/1.6.11 npm http 304 https://registry.npmjs.org/debug/2.2.0 npm http 304 https://registry.npmjs.org/socket.io-adapter/0.4.0 npm http 304 https://registry.npmjs.org/has-binary/0.1.7 npm http 304 https://registry.npmjs.org/socket.io-client/1.4.8 npm http https://registry.npmjs.org/engine.io/-/engine.io-1.6.11.tgz npm http https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-0.4.0.tgz npm http https://registry.npmjs.org/socket.io-client/-/socket.io-client-1.4.8.tgz npm http https://registry.npmjs.org/has-binary/-/has-binary-0.1.7.tgz npm http 200 https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.6.tgz npm http 200 https://registry.npmjs.org/engine.io/-/engine.io-1.6.11.tgz npm http 200 https://registry.npmjs.org/has-binary/-/has-binary-0.1.7.tgz npm http 200 https://registry.npmjs.org/socket.io-client/-/socket.io-client-1.4.8.tgz npm http 200 https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-0.4.0.tgz npm http https://registry.npmjs.org/isarray/0.0.1 npm http https://registry.npmjs.org/socket.io-parser/2.2.2 npm http https://registry.npmjs.org/ms/0.7.1 npm http https://registry.npmjs.org/json3/3.3.2 npm http https://registry.npmjs.org/component-emitter/1.1.2 npm http https://registry.npmjs.org/benchmark/1.0.0 npm http https://registry.npmjs.org/base64id/0.1.0 npm http https://registry.npmjs.org/engine.io-parser/1.2.4 npm http https://registry.npmjs.org/ws/1.1.0 npm http https://registry.npmjs.org/accepts/1.1.4 npm http 304 https://registry.npmjs.org/socket.io-parser/2.2.2 npm http 304 https://registry.npmjs.org/isarray/0.0.1 npm http https://registry.npmjs.org/engine.io-client/1.6.11 npm http https://registry.npmjs.org/component-emitter/1.2.0 npm http https://registry.npmjs.org/component-bind/1.0.0 npm http https://registry.npmjs.org/indexof/0.0.1 npm http https://registry.npmjs.org/object-component/0.0.3 npm http https://registry.npmjs.org/to-array/0.1.4 npm http https://registry.npmjs.org/parseuri/0.0.4 npm http 304 https://registry.npmjs.org/json3/3.3.2 npm http 304 https://registry.npmjs.org/ms/0.7.1 npm http https://registry.npmjs.org/backo2/1.0.2 npm http 304 https://registry.npmjs.org/benchmark/1.0.0 npm http 304 https://registry.npmjs.org/base64id/0.1.0 npm http 304 https://registry.npmjs.org/component-emitter/1.1.2 npm http https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.2.tgz npm http 304 https://registry.npmjs.org/engine.io-parser/1.2.4 npm http 304 https://registry.npmjs.org/ws/1.1.0 npm http https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz npm http 304 https://registry.npmjs.org/engine.io-client/1.6.11 npm http 304 https://registry.npmjs.org/component-emitter/1.2.0 npm http 304 https://registry.npmjs.org/accepts/1.1.4 npm http 304 https://registry.npmjs.org/component-bind/1.0.0 npm http 304 https://registry.npmjs.org/indexof/0.0.1 npm http https://registry.npmjs.org/base64id/-/base64id-0.1.0.tgz npm http 304 https://registry.npmjs.org/object-component/0.0.3 npm http https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http https://registry.npmjs.org/json3/-/json3-3.3.2.tgz npm http https://registry.npmjs.org/ms/-/ms-0.7.1.tgz npm http https://registry.npmjs.org/benchmark/-/benchmark-1.0.0.tgz npm http 304 https://registry.npmjs.org/to-array/0.1.4 npm http 304 https://registry.npmjs.org/parseuri/0.0.4 npm http 304 https://registry.npmjs.org/backo2/1.0.2 npm http https://registry.npmjs.org/ws/-/ws-1.1.0.tgz npm http https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-1.2.4.tgz npm http https://registry.npmjs.org/engine.io-client/-/engine.io-client-1.6.11.tgz npm http https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.0.tgz npm http https://registry.npmjs.org/accepts/-/accepts-1.1.4.tgz npm http https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz npm http https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz npm http https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz npm http https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz npm http https://registry.npmjs.org/parseuri/-/parseuri-0.0.4.tgz npm http 200 https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-2.2.2.tgz npm http 200 https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz npm http 200 https://registry.npmjs.org/ms/-/ms-0.7.1.tgz npm http 200 https://registry.npmjs.org/base64id/-/base64id-0.1.0.tgz npm http 200 https://registry.npmjs.org/benchmark/-/benchmark-1.0.0.tgz npm http 200 https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http 200 https://registry.npmjs.org/json3/-/json3-3.3.2.tgz npm http 200 https://registry.npmjs.org/ws/-/ws-1.1.0.tgz npm http 200 https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-1.2.4.tgz npm http 200 https://registry.npmjs.org/engine.io-client/-/engine.io-client-1.6.11.tgz npm http 200 https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.0.tgz npm http 200 https://registry.npmjs.org/accepts/-/accepts-1.1.4.tgz npm http 200 https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz npm http 200 https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz npm http 200 https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz npm http 200 https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz npm http 200 https://registry.npmjs.org/parseuri/-/parseuri-0.0.4.tgz npm http https://registry.npmjs.org/json3/3.2.6 npm http https://registry.npmjs.org/debug/0.7.4 npm http https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http 304 https://registry.npmjs.org/json3/3.2.6 npm http 304 https://registry.npmjs.org/debug/0.7.4 npm http https://registry.npmjs.org/json3/-/json3-3.2.6.tgz npm http 200 https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http https://registry.npmjs.org/debug/-/debug-0.7.4.tgz npm http 200 https://registry.npmjs.org/json3/-/json3-3.2.6.tgz npm http https://registry.npmjs.org/mime-types npm http https://registry.npmjs.org/negotiator/0.4.9 npm http 304 https://registry.npmjs.org/negotiator/0.4.9 npm http 200 https://registry.npmjs.org/debug/-/debug-0.7.4.tgz npm http https://registry.npmjs.org/after/0.8.1 npm http https://registry.npmjs.org/arraybuffer.slice/0.0.6 npm http https://registry.npmjs.org/base64-arraybuffer/0.1.2 npm http https://registry.npmjs.org/has-binary/0.1.6 npm http https://registry.npmjs.org/blob/0.0.4 npm http https://registry.npmjs.org/utf8/2.1.0 npm http https://registry.npmjs.org/negotiator/-/negotiator-0.4.9.tgz npm http 304 https://registry.npmjs.org/mime-types npm http 304 https://registry.npmjs.org/blob/0.0.4 npm http https://registry.npmjs.org/blob/-/blob-0.0.4.tgz npm http 304 https://registry.npmjs.org/utf8/2.1.0 npm http https://registry.npmjs.org/options npm http https://registry.npmjs.org/ultron npm http 304 https://registry.npmjs.org/arraybuffer.slice/0.0.6 npm http 304 https://registry.npmjs.org/after/0.8.1 npm http 304 https://registry.npmjs.org/base64-arraybuffer/0.1.2 npm http 304 https://registry.npmjs.org/has-binary/0.1.6 npm http https://registry.npmjs.org/utf8/-/utf8-2.1.0.tgz npm http 200 https://registry.npmjs.org/negotiator/-/negotiator-0.4.9.tgz npm http 304 https://registry.npmjs.org/ultron npm http https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz npm http https://registry.npmjs.org/after/-/after-0.8.1.tgz npm http https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.2.tgz npm http https://registry.npmjs.org/has-binary/-/has-binary-0.1.6.tgz npm http 200 https://registry.npmjs.org/blob/-/blob-0.0.4.tgz npm http 200 https://registry.npmjs.org/has-binary/-/has-binary-0.1.6.tgz npm http 200 https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.2.tgz npm http 200 https://registry.npmjs.org/utf8/-/utf8-2.1.0.tgz npm http 200 https://registry.npmjs.org/after/-/after-0.8.1.tgz npm http 304 https://registry.npmjs.org/options npm http https://registry.npmjs.org/better-assert npm http 200 https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz npm http 304 https://registry.npmjs.org/better-assert npm http https://registry.npmjs.org/callsite/1.0.0 npm http 304 https://registry.npmjs.org/callsite/1.0.0 npm http https://registry.npmjs.org/mime-db npm http https://registry.npmjs.org/has-cors/1.1.0 npm http https://registry.npmjs.org/ws/1.0.1 npm http https://registry.npmjs.org/xmlhttprequest-ssl/1.5.1 npm http https://registry.npmjs.org/parsejson/0.0.1 npm http https://registry.npmjs.org/parseqs/0.0.2 npm http https://registry.npmjs.org/component-inherit/0.0.3 npm http https://registry.npmjs.org/yeast/0.1.2 npm http https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-1.2.4.tgz npm http 304 https://registry.npmjs.org/mime-db npm http 304 https://registry.npmjs.org/parseqs/0.0.2 npm http 304 https://registry.npmjs.org/component-inherit/0.0.3 npm http https://registry.npmjs.org/parseqs/-/parseqs-0.0.2.tgz npm http 304 https://registry.npmjs.org/ws/1.0.1 npm http 304 https://registry.npmjs.org/has-cors/1.1.0 npm http https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz npm http 304 https://registry.npmjs.org/yeast/0.1.2 npm http 304 https://registry.npmjs.org/xmlhttprequest-ssl/1.5.1 npm http 200 https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz npm http 200 https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-1.2.4.tgz npm http https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz npm http https://registry.npmjs.org/ws/-/ws-1.0.1.tgz npm http https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.1.tgz npm http https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz npm http 200 https://registry.npmjs.org/parseqs/-/parseqs-0.0.2.tgz npm http 200 https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz npm http 200 https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz npm http 200 https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz npm http 200 https://registry.npmjs.org/ws/-/ws-1.0.1.tgz npm http 200 https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.1.tgz npm http 304 https://registry.npmjs.org/parsejson/0.0.1 npm http https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz npm http https://registry.npmjs.org/after/-/after-0.8.1.tgz npm http https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz npm http https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.2.tgz npm http https://registry.npmjs.org/has-binary/-/has-binary-0.1.6.tgz npm http https://registry.npmjs.org/blob/-/blob-0.0.4.tgz npm http 200 https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz npm http 200 https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz npm http 200 https://registry.npmjs.org/after/-/after-0.8.1.tgz npm http 200 https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.2.tgz npm http 200 https://registry.npmjs.org/has-binary/-/has-binary-0.1.6.tgz npm http 200 https://registry.npmjs.org/blob/-/blob-0.0.4.tgz socket.io@1.4.8 node_modules\socket.io ├── has-binary@0.1.7 (isarray@0.0.1) ├── debug@2.2.0 (ms@0.7.1) ├── socket.io-parser@2.2.6 (isarray@0.0.1, component-emitter@1.1.2, json3@3.3.2, benchmark@1.0.0) ├── engine.io@1.6.11 (base64id@0.1.0, ws@1.1.0, engine.io-parser@1.2.4, accepts@1.1.4) ├── socket.io-adapter@0.4.0 (socket.io-parser@2.2.2) └── socket.io-client@1.4.8 (component-emitter@1.2.0, to-array@0.1.4, indexof@0.0.1, component-bind@1.0.0, backo2@1.0.2, object-component@0.0.3, parseuri@0.0.4, engine.io-client@1.6.11) c:\chatapplication>node app.js c:\chatapplication\app.js:45 }); ^ syntaxerror: unexpected token ) @ module._compile (module.js:439:25) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12) @ function.module.runmain (module.js:497:10) @ startup (node.js:119:16) @ node.js:901:3 c:\chatapplication>
any ideas how can resolve issue, cause don't seem have syntax errors in opinion tbh :/
thanks in advance.
app.get structure is:
app.get(path, callback [, callback ...])
correct code is:
app.get('/', function(req, res){ //and declare "http response" , . "sendfile" because, going create file called "index.html" want client whenever goes "localhost:3000". //then create "directory name" + "index.html" web page. res.sendfile(__dirname + '/index.html'); });
more express routing here.
Comments
Post a Comment