Error settting up atom with nodejs on ubuntu - node.js

I am trying to set up nodejs with atom on ubuntu 16.10. I followed the steps given in this link. But when I edit the ~/.atom/config.cson file to
runner:
scopes:
js:”nodejs”
as given in the link, Atom gives an error
Unexpected new line after runner:
How do I get this correct?
EDIT
After using Dan Lowe's code, the atom error disappeared but the code doesnt compile.
#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, 'localhost');
console.log('Server running at http://localhost:8080/');
It gives the error
./server.js: line 3: syntax error near unexpected token `('
./server.js: line 3: `var http = require('http');'
Is it not able to see nodejs?

If this is the actual config you are using, you have two problems.
The lines are not indented.
Around nodejs are smart-quotes, not normal double quotes. That is not valid syntax here.
You probably want this instead.
runner:
scopes:
js: "nodejs"

Related

syntax error near unexpected token `(' in node js

I started setting up a node app but it prompt me this
syntax error near unexpected token `('
'/app.js: line 1: `var http = require("http");
this is my code for app.js
var http = require("http");
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, 'localhost');
console.log('Server running at http://localhost:8080/');
can anyone help me in this
This is probably because you are running your script as if it is a bash script.
You have two options
run your program with the command $ node your_pgm.js
add the line #!/path/to/node to the beginning of your program (it must be the very first line)
Why are you typing in bash?
Please try to type "$ node" first and then you should see:
Welcome to Node.js v14 (or any version that you have installed).

Error getting when executing nodejs through command prompt

I have the below code in Nodejs and tried to execute the same through command line as well as in browser, but getting "unexpected identifier" error.
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.end('<b>Running in server...</b>');
}).listen('3000', '127.0.0.1');
File name created is module3.js
I am very new to nodejs. So can anyone please help me to resolve this. Thanks!!
If you like to run file, do it as usual for shell comman line (interpreter file):
D:\nodejs> node module3.js
If you like to work in nodejs command line, you need to load module by require and it will be loaded and evaluated:
D:\nodejs> node
> require('./module3')
If your module exports some function you may to call it:
D:\nodejs> node
> require('./module3')()
Check about exports here

node js syntaxError: Unexpected Identifier

There are a lot of questions regarding this issue, but none of them were helpful, as they fix a concrete syntax error. I'm really new in Javascript programming, starting it a few weeks ago.
I would like to run my scripts on Node.js, but for some reason it is not working. It gives me the next error: SyntaxError: Unexpected identifier
I'm talking about very simple scripts, like this:
var orders =[
{amount: 250 },
{amount: 400 },
{amount: 100 },
{amount: 325 },
];
var totalAmount=0
for(var i=0; i< orders.length; i++){
totalAmount+=orders[i].amount;
}
console.log(totalAmount);
What basically is working on my browser smoothly.
I'm really sorry to bother you with such small silly things, but I would appreciate any help. It's easier to work with my scripts on node js.
How are you running your scripts in nodejs? If you are just starting with js, try it in browser. Or if you really want it with nodejs.
Download the Windows executable here: http://nodejs.org/#download
Copy the file to C:\
Create C:\hello.js
Paste in the following content:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at 127.0.0.1:1337');
Save the file
Start -> Run... -> cmd
c: C:>node hello.js
It seems I've got the problem, I tried to run the things through the language shell window instead of node.js command prompt.It's silly I know, but it wasn't specified where to run the node commands. By the way I found out more, then I was expecting. I don't regret to register here, you have a lot of material here. Thank you guys.
I hope one day I can help out someone.

node server.js is not working due to syntax error?

I am trying to learn node.js and like many others, the first step is like How to run server written in js with Node.js
However, my problem is syntax problem? (as follows)
server.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
That's a different program called Node. You may want to uninstall it, then install actual Node from here:https://nodejs.org/en/download/

Cannot run node.js example. module.js:340 throw err cannot find module

When I type in node example.js to my command prompt it gives me an error message.
This is the code I'm using.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, 'localhost');
console.log('Server running at http://localhost:1337/');
I got that directly from the node.js website and it worked last night. It won't work today. Some help would be appreciated please.
Node.js looks for the file you pass it in the current directory.
If the file only exists in a different directory, it will not be able to find it.
You need to either save the file to the correct directory, or use cd to switch to the directory containing the file.

Resources