Reputation: 1634
I've created an ubuntu instance on my university server. I've installed NodeJS and NPM and can send files with a FTP connection.
I sent following NodeJS webserver file to my intance and want to run it on the instance ip-adress.
var http = require(“http“);
http.createServer(function(request, response) {
response.writeHead(200, {‚content-type’: ‚text/plain‚});
response.write(‘Hello World’);
response.end;
}).listen(3000‚141.28.107.7);
console.log(“server is running“);
When I run this file with
sudo nodejs server.js
I'm getting the following error message:
sudo: unable to resolve host nodejs
/home/robin/files/webserver.js:1
(function (exports, require, module, __filename, __dirname) { var http = require(“http“);
^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
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 Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
Where's my error in reasoning? Thanks!
Upvotes: 2
Views: 3712
Reputation: 7912
You seem to be using weird quotes : “
. Use standard double quotes "
or single quotes '
.
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World');
response.end();
}).listen(3000‚'141.28.107.7');
console.log('server is running');
Upvotes: 6