$ babel and $ babel-node don't launch the REPL - node.js

I'm trying to setup babel on Ubuntu 14.04 but it doesn't seem to be working!
Here are some outputs that may be required:
$ which node
/usr/sbin/node
$ which nodejs
/usr/bin/nodejs
$ which babel
/usr/local/bin/babel
$ which babel-node
/usr/local/bin/babel-node
When I execute babel or babel-node the prompt just returns. The same happens on executing the commands with a filename as argument. (The file has just console.log("hello").
How do I fix this?

The /usr/sbin/node vs /usr/bin/nodejs issue has been covered in Cannot install packages using node package manager in Ubuntu but basically Ubuntu has a separate node package that is NOT Node.js. The package for Node.js on Ubuntu is called nodejs. If you have both installed, it means your scripts will try to run using the other unrelated application. One option is to symlink nodejs to node.
The best solution however would be to use something like nvm to install node for your user without installing it globally. Then you can install and update node versions extremely easily, and your PATH will always reference node properly.

Changing node to nodejs in the first line of /usr/local/bin/babel-node and /usr/local/bin/babel solves it.

Related

switching node versions using n

[root#xx.xx.xx.xx xxxx]# n
installed : v14.8.0 to /usr/local/bin/node
active : v10.21.0 at /bin/node
Installed node version 14.8.0 using n. Not sure how 10.21.0 was installed. Cannot delete or switch versions. I am using pm2 process manager and need the versions switched i.e dont want to run n run v14.8.0 server.js i would rather change the active version globally, so that running pm2 start would not need to specify a specific version. Please help.
First, you can explicitly select /usr/local/bin/node by creating a file like
/usr/local/bin/node server.js
Make sure to rename it to something ending with .sh
Then to run it with pm2 you can do pm2 run yourfilename.sh
Second, you can use a shebang line in server.js, so the first line must be
#!/usr/local/bin/node
And you can run your script the way you were doing it before

How can I get the slc command to work on Ubuntu?

I have installed Strongloop using npm install -g strongloop on my Ubuntu 14.04 server. The slc command does not work. It says
The program 'slc' is currently not installed. You can install it by typing:
sudo apt-get install heimdal-multidev
How can I get it to run the Strongloop CLI instead of looking for this package? I have added this to my PATH and it still doesn't work. Any ideas?
Other Strongloop commands, like sl-build work and strongloop is listed in npm list -g.
Ubuntu 14 with node.js 4.1.2
By default somehow slc is not created or not added to PATH.
I solved this problem by adding symlink:
sudo ln -s /usr/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
A soft link named slc should have been created at /usr/local/bin which will point to strongloop binary.
Please verify if the following exists.
/usr/local/lib/node_modules/strongloop/bin/slc
If no, then strongloop did not get installed successfully, otherwise verify the existence of the softlink slc at /usr/local/bin/.
/usr/local/bin/slc -> /usr/local/lib/node_modules/strongloop/bin/slc
If yes, then /usr/local/bin needs to be added to the $PATH, otherwise create the softlink and verify that /usr/local/binin $PATH.
Looks like the Node installation that optionally comes with a Digital Ocean Droplet installs to a different location that's not in $PATH. I'm pretty sure that was the issue. Anyways, I fixed it by spinning up a server without Node pre-installed and followed this guide. Just use npm install -g strongloop instead of strong-cli because the latter has been deprecated.
Ubuntu 14.04 with node.js 4.4.2 (LTS) :
The installation of strongloop was done without any errors but slc was not added to the PATH. I solved this problem by adding the symlink:
sudo ln -s /usr/local/lib/node_modules/strongloop/bin/slc.js /usr/bin/slc
Actually i am not sure my case matches with yours but i want to share my experience. i got the same message anyway.
I realized that i had changed prefix of global packets before. Then i checked prefix with the following command.
$ npm config get prefix
/home/myUser/.node_modules_global
Then i added the path to PATH variable (but .profile, .bash_profile files will be better) in active command line window and problem solved.

Can't build atom on Linux

I followed these steps to build atom on Linux on my own.
After cloning atom, i tried to run script/build. But i get an error "No such file or directory".
Node v0.10.31
Npm v0.10.31
I don't now how can I run these atom-build-script.
After searching, i found a solution to fix this issue.
[1] after installing node via apt, its command is nodejs, not node like its recommended to use these build-script
[1.1] after removing apt's node installation, i build node by my own
[2] run which node, to find out where you install node
[3] to run the build-script: /opt/node/bin/node your-atom-path/script/build
additional information how to fix from atom-github-build-instructions
"/usr/bin/env: node: No such file or directory
If you get this notice when attempting to script/build, you either do not have Node.js installed, or node isn't identified as Node.js on your machine. If it's the latter, entering sudo ln -s /usr/bin/nodejs /usr/bin/node into your terminal may fix the issue."

nodejs is already the newest version but "node -v" doesn't give a response

This is really confusing me. If I type "node -v" into the command line, there is no response - it just gives me the $ prompt again. Trying to install node with sudo npm install nodejs gives the response nodejs is already the newest version.
How can I debug this to find out what's going on?
nodejs -v solved the problem.
In some linux distributions node executable is mapped into nodejs.
Are you trying to print the node version? If yes then try
$ node --version
Node is by default installed on /usr/bin/ directory on linux OS it means it should run with normal user privilege but node include some tools that required Superuser privilege so ...
Instead running
node -v
run
sudo node -v
hope it will work...keep coding

Install mocha on VirtualBox with Ubuntu image

I'm using Oracle VirtualBox in Windows 7 with an image of Ubuntu 13.04 x86.
I've already downloaded a github project, I've run:
sudo npm install -g mocha
sudo npm install mocha
npm install
nodejs is installed (nodejs --version retrieves v0.10.25)
If I run:
which mocha
I get: /usr/bin/mocha
Then, I run:
mocha test/test1.js
I just get the command prompt, nothing happens, I don't see the tests running.
I went to the mocha folder inside node_modules/mocha and I see two files: mocha and _mocha, I run both and nothing happens
When I say "I just get the command prompt", this is what I can see:
ubuntu#ubuntu-VirtualBox:~/guillermo/myproject$ mocha --reporters
ubuntu#ubuntu-VirtualBox:~/guillermo/myproject$
Any advise?
Thanks!!! Guillermo.
You probably installed the wrong Ubuntu package for node.js. If you did sudo apt-get install node, then the package "ax25-node" is installed instead of node.js.
See this page on how to install node.js on Ubuntu using nvm.
If you want to use ubuntu's package repository for node.js, then do sudo apt-get install nodejs, and the resulting binary is called nodejs instead of node.

Resources