NPM install fails with NVM and Docker - node.js

I am using NVM to install Node.js 16.15.0 inside a Docker container.
I get an error when running npm ci:
npm ERR! command failed
npm ERR! command sh -c node lib/install.js
npm ERR! /atomix/node_modules/npm-conf/lib/conf.js:169
npm ERR! throw err;
npm ERR! ^
npm ERR!
npm ERR! Error: EACCES: permission denied, stat '/root/.nvm/versions/node/v16.15.0'
npm ERR! at Object.statSync (fs.js:898:3)
npm ERR! at Conf.loadUser (/atomix/node_modules/npm-conf/lib/conf.js:162:21)
npm ERR! at module.exports (/atomix/node_modules/npm-conf/index.js:32:7)
npm ERR! at Object.<anonymous> (/atomix/node_modules/get-proxy/index.js:2:36)
npm ERR! at Module._compile (internal/modules/cjs/loader.js:936:30)
npm ERR! at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
npm ERR! at Module.load (internal/modules/cjs/loader.js:790:32)
npm ERR! at Function.Module._load (internal/modules/cjs/loader.js:703:12)
npm ERR! at Module.require (internal/modules/cjs/loader.js:830:19)
npm ERR! at require (internal/modules/cjs/helpers.js:68:18) {
npm ERR! errno: -13,
npm ERR! syscall: 'stat',
npm ERR! code: 'EACCES',
npm ERR! path: '/root/.nvm/versions/node/v16.15.0'
npm ERR! }
My Dockerfile:
FROM trzeci/emscripten
EXPOSE 8080/tcp
RUN apt update \
&& apt install libglew-dev -y \
&& wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash \
&& apt install htop \
&& apt install procps -y
ENV NVM_DIR /root/.nvm
ENV NODE_VERSION 16.15.0
RUN chmod +x $HOME/.nvm/nvm.sh
RUN . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
WORKDIR /atomix
RUN npm i flow-typed -g
# NPM 7+ automatically installs peer deps so disable this as it fails our install
RUN npm config set legacy-peer-deps true
These installation instructions for NVM are copied from NVM itself.
When I roll it back from 16.15.0 to 10.16.0 (which I know works) it works successfully. Why does the newer version of Node.js fail?

I would suggest using one of the official Node.JS Docker images for whatever part you need Node for. You can use a build arg to specify the version.
Use a multi-stage build to create whatever assets you need for the Node stage.
ARG NODE_VERSION=16.5
# Build stage
FROM emscripten/emsdk AS emcc
WORKDIR /build
COPY your-src-files/ ./
RUN emcc ...
# Run
FROM node:${NODE_VERSION}
WORKDIR /atomix
RUN npm config set legacy-peer-deps true
RUN npm i flow-typed -g
COPY --from=emcc /build/your-compiled-files ./
RUN ...
To change the Node version, you simply build the image with a NODE_VERSION build arg...
docker build --build-arg NODE_VERSION=17 .

Related

Docker image build but can't see in browser

I have an Angular project which I built an image, it runs in local, in other words, I can launch it with npm start, and see my app on localhost:4200.
But when I build it, I can't see the project in the browser on the same url. It's just my browser telling me it's unable to connect. I also used Postman same error.
Dockerfile :
FROM node:latest
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 4200
CMD [ "npm", "start" ]
The command
docker build -t test-front .
...
docker run -it -p 4200:4200 test-front
It builds the image and run it well, but I can't access it on the browser.
I used the answer to this question to remake my Dockerfile:
Cannot find module for a node js app running in a docker compose environment
What I did:
I did a `docker exec -it NAME_OF_THE_CONTAINER /bin/bash` to get inside the container, I then retried `npm start` inside the container.
Since the port 4200 was in use, it asked me to use another port:
root#a66d5cff3e64:/usr/src/app# npm start
> xxx#0.0.0 start
> ng serve
? Port 4200 is already in use.
Would you like to use a different port? Yes
✔ Browser application bundle generation complete.
...
** Angular Live Development Server is listening on localhost:43225, open your browser on http://localhost:43225/ **
The project was launching correctly in the container, no error message.
I think, the container doesn't expose the port correctly.
Checking port
I used the command:
user#user:~/front$ docker port <container_name>
4200/tcp -> 0.0.0.0:4200
4200/tcp -> :::4200
This is what I have.
Small detail
I'd like to precise, that using node:boron in Dockerfile, made the docker run break. It didn't worked when I used docker run command.
With the message:
> xxxxxx#0.0.0 start /usr/src/app
> ng serve
/usr/src/app/node_modules/#angular/cli/bin/ng:26
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
npm ERR! Linux 5.11.0-22-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.17.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! xxxx#0.0.0 start: `ng serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xxxx#0.0.0 start script 'ng serve'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the xxx package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng serve
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs xxx
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls xxx
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/src/app/npm-debug.log
I've changed my last line to CMD [ "npm", "run", "ng", "serve", "-host", "0.0.0.0" ].
I can build the image, but when I run it, I get:
> t-maj-voltron-front#0.0.0 ng
> ng "serve" "0.0.0.0"
Project '0.0.0.0' does not exist.
npm notice
npm notice New minor version of npm available! 7.15.1 -> 7.19.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.19.0
npm notice Run npm install -g npm#7.19.0 to update!
npm notice
a working Dockerfile:
# base image
FROM node:12.14
# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
# set working directory
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install -g #angular/cli#7.3.9
# add app
COPY . /app
EXPOSE 4200
# start app
CMD ng serve --host 0.0.0.0
I believe you're missing the port forwarding between the exposed port and your local host.
You can portforward via the -p or --expose flag and the <localport>:<containerport>
In your case:
docker run -it -p 4200:4200 test-front
Will forward traffic from localhost:4200 into your container
EDIT
I did some more reading and it looks like there's an additional step when working with angular in docker.
try editing your npm start command to ng serve --host 0.0.0.0. As explained very thoroughly by Juan adding the --host flag will "listen to all the interfaces from the container"

Trying Laravel jetstream but getting an error on "npm run dev"

lam getting the error below while running npm run dev
[webpack-cli] TypeError: this.program.configureOutput is not a function
at new WebpackCLI (/home/vagrant/sites/ecom/node_modules/webpack-cli/lib/webpack-cli.js:19:22)
at runCLI (/home/vagrant/sites/ecom/node_modules/webpack-cli/lib/bootstrap.js:7:21)
at Object. (/home/vagrant/sites/ecom/node_modules/webpack-cli/bin/cli.js:23:5)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at runCli (/home/vagrant/sites/ecom/node_modules/webpack/bin/webpack.js:54:2)
npm ERR! code 2
npm ERR! path /home/vagrant/sites/ecom
npm ERR! command failed
npm ERR! command sh -c mix
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2021-03-19T11_14_07_947Z-debug.log
npm ERR! code 2
npm ERR! path /home/vagrant/sites/ecom
npm ERR! command failed
npm ERR! command sh -c npm run development
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2021-03-19T11_14_07_974Z-debug.log
First, try to update your node.js file and then run "npm run dev" and if you again faced the same problem follow the following steps:
Step1: composer update
Step2: rm -rf node_modules
Step3: npm cache clear --force
Step4: npm install
Step5: npm outdated
In this step, it will update your laravel-mix version, it is in the package.json.
Step6: npm install
Step7: npm run dev
After all these steps, everything is good.
I hope it solve your problem.
I came across this problem when trying to build and run webpack (and webpack-cli locally), after check out from Github (not at all related to Laravel).
I found that I forgot to run yarn install for webpack-cli which lead to the issue that an existing version of commander#6 was used, but webpack-cli requires commander#7.
npm list commander should tell you that the webpack-cli dependency is unsatisfied. yarn install should fix it.

Performing a npm install via Docker on a windows host

I'm trying to create a docker dev tools container for a devlopement environment on a windows host via docker toolbox but I have some trouble running the npm install command.
It worked fine on a linux host but on the windows host I got the following error :
npm ERR! Linux 4.1.13-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm v3.3.12
npm ERR! path /var/www/site/.npm/gulp/3.9.0/package.tgz.e87c24357cd6065ee71ce44c6f23673b
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/var/www/site/.npm/gulp/3.9.0/package.tgz.e87c24357cd6065ee71ce44c6f23673b' -> '/var/www/site/.npm/gulp/3.9.0/package.tgz'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Linux 4.1.13-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v5.5.0
npm ERR! npm v3.3.12
npm ERR! path npm-debug.log.39d944b679d410e5293d6721cbc8287a
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename 'npm-debug.log.39d944b679d410e5293d6721cbc8287a' -> 'npm-debug.log'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/site/npm-debug.log
Here is my Dockerfile :
FROM node:latest
RUN apt-get update
RUN apt-get install vim -y
RUN useradd -ms /bin/bash node
RUN echo "fs.inotify.max_user_watches=100000" > /etc/sysctl.conf
ADD . /var/www/site
RUN chown -R node:node /var/www/site
RUN chown -R node:node /usr/local/lib/node_modules
RUN chown -R node:node /usr/local/bin
USER node
ENV HOME /var/www/site
WORKDIR /var/www/site
RUN npm install -g bower
RUN npm install --global gulp -y
EXPOSE 80 8080 35729
In Docker quickstart terminal, I use the following commands :
Building the image (works fine)
docker build -t dev_tools .
Building the container (works fine)
docker run --name=dev_tools_container -t --rm -v "//c/Users/Public/site:/var/www/site" --net=host dev_tools
Trying to install npm dependencies (shoots the error):
docker exec -it dev_tools_container npm install
Thank you for your time !
Instead of
RUN npm install --global gulp -y
use
RUN sudo npm install --global gulp -y
You try to install gulp as a global package from user node (not superuser).
Or install gulp before switch user to node.
USER node
RUN npm install --global gulp -y
EDIT:
boot2docker is based on VirtualBox. Virtualbox does not allow symlinks on shared folders for security reasons.
To enable symlinks You must set VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME to 1. (Here is link to description how to do it on Vargrant: Symbolic links and synced folders in Vagrant)
VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1
Replace VM_NAME and SHARE_NAME and restart VirtualBox.
Another solution is add --no-bin-link to npm:
RUN npm install -g bower --no-bin-link
RUN npm install --global gulp -y --no-bin-link
EDIT 2
By default Windows 7 security policy does not allow creating symlinks as it's a potential security threat. If user is not in Administrators group run secpol.msc and navigate to Local Policies-User Rights Assignments and add your user to Create symbolic links.
If your user belongs to Administrators group then start VirtualBox with Run as Administrator.
You can mount node_modules as a volume, so it will be a Linux filesystem inside the Docker container. Add this to your Dockerfile:
VOLUME /var/www/site/node_modules
You will see the directory at C:Users/Public/site/node_modules because it is necessary for a mount point, but you will not see any contents unless you are inside the container.

Trying to use Appium on Ubuntu but getting node.js:134 error

I've installed node with
sudo apt-get install -y nodejs
and appium with
sudo npm install -g appium
In both cases I was forced to use sudo as I was on Ubuntu. The appium page at https://github.com/appium/appium/blob/master/README.md says don't use sudo but I believe that with Ubuntu it's ok (and necessary) to use sudo as directed on the node page at https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
When I try and start appium with appium & or even just
appium
I get
$ appium
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object prototype may only be an Object or null
at Function.create (native)
at Object.inherits (util.js:425:27)
at Object.<anonymous> (/usr/lib/node_modules/appium/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/readable-stream/lib/_stream_readable.js:63:6)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object.<anonymous> (/usr/lib/node_modules/appium/node_modules/npmlog/node_modules/are-we-there-yet/node_modules/readable-stream/readable.js:1:90)
at Module._compile (module.js:402:26)
I upgraded node but it hasn't seemed to help:
$ node -v
v0.12.2
15:04:28 durrantm Castle2012 /home/durrantm/Dropbox/_/appium_mobile_testing/appium master
$ appium
error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.
However when I uninstall node and then try re-installing it without sudo, as indicated, I get:
$ apt-get install nodejs
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
I tried building node from source locally with
$ mkdir ~/local
$ ./configure --prefix=~/local
creating ./icu_config.gypi
{ 'target_defaults': { 'cflags': [],
'default_configuration': 'Release',
'defines': [],
'include_dirs': [],
'libraries': []},
'variables': { 'clang': 0,
'gcc_version': 48,
'host_arch': 'x64',
'icu_small': 'false',
'node_install_npm': 'true',
'node_prefix': '/home/durrantm/local',
'node_shared_cares': 'false',
'node_shared_http_parser': 'false',
'node_shared_libuv': 'false',
'node_shared_openssl': 'false',
'node_shared_v8': 'false',
'node_shared_zlib': 'false',
'node_tag': '',
'node_use_dtrace': 'false',
'node_use_etw': 'false',
'node_use_mdb': 'false',
'node_use_openssl': 'true',
'node_use_perfctr': 'false',
'openssl_no_asm': 0,
'python': '/usr/bin/python',
'target_arch': 'x64',
'uv_library': 'static_library',
'uv_parent_path': '/deps/uv/',
'uv_use_dtrace': 'false',
'v8_enable_gdbjit': 0,
'v8_enable_i18n_support': 0,
'v8_no_strict_aliasing': 1,
'v8_optimized_debug': 0,
'v8_random_seed': 0,
'v8_use_snapshot': 'true',
'want_separate_host_toolset': 0}}
creating ./config.gypi
creating ./config.mk
$ make
...
$ make install
...
but it didn't seem to help:
$ npm install -g appium
npm ERR! tar.unpack untar error /home/durrantm/.npm/appium/1.3.7/package.tgz
npm ERR! Linux 3.13.0-49-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "appium"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! path /usr/local/lib/node_modules/appium
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/appium'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/appium']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/appium',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/appium',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:95:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /home/durrantm/Downloads/node/npm-debug.log
15:47:13 durrantm Castle2012 /home/durrantm/Downloads/node master
$ appium
error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.
I also did
sudo chown -R $(whoami) ~/.npm
and
sudo npm install -g appium
...
lots of compile outpout, not errors, seems ok
...
but still I get
$ appium
error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.
As you already mentioned, Appium should not be installed with sudo.
And I won't recommend you to install node via apt, didn't work for me.
Better use homebrew - this will allow you to install Appium to a home directory without sudo. Try following:
Uninstall node that you previously installed with apt: sudo apt-get remove node
Follow instructions and install homebrew. After that install node with: brew install node
Now try: npm install -g appium
And if you'll face permissions issues with .npm folder in home path, than use sudo chown -R $(whoami) ~/.npm that you also mentioned.

NPM install giving error installing express

When I give command npm install express it throws following error. On ubuntu machine
gaurav#gaurav-Mini-Monster:~/TestScripts$ sudo npm install -g express
npm ERR! error installing express#3.3.3 Error: Unsupported
npm ERR! error installing express#3.3.3 at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing express#3.3.3 at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing express#3.3.3 at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing express#3.3.3 at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing express#3.3.3 at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:470:3)
npm ERR! error installing express#3.3.3 at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing express#3.3.3 at Array.forEach (native)
npm ERR! error installing express#3.3.3 at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back express#3.3.3 Error: UNKNOWN, Unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect#2.8.3
npm ERR! Required: {"node":">= 0.8.0"}
npm ERR! Actual: {"npm":"1.0.106","node":"0.5.11-pre"}
npm ERR!
npm ERR! System Linux 3.2.0-48-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /home/gaurav/TestScripts
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! code ENOTSUP
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/gaurav/TestScripts/npm-debug.log
npm not ok
I also tried
sudo npm install express
npm install -g express
sudo npm install -g express
Nothing works.
Node is so easy to install manually. I like doing it this way too because it's really easy to switch versions.
This is also great because you don't need to add some external package repository to apt, and you don't have to wait for those repositories to update when node releases a new version. You can get updates as soon as they're released.
# make a `~/.nodes/ folder
mkdir -p ~/.nodes && cd ~/.nodes
# download the binaries from nodejs.org
# in this case, here's the linux version
curl -O http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-x64.tar.gz
# extract
tar -xzf node-v0.10.12-linux-x64.tar.gz
# rename folder to 0.10.12
mv node-v0.10.12-linux-x64 0.10.12
# create a `current` symlink
ln -s 0.10.12 current
# prepend ~/.nodes/bin to your path
# you'll want to save this in ~/.bashrc or ~/.zshrc or something
export PATH="~/.nodes/current/bin:$PATH"
# cleanup
rm ~/.nodes/node-v0.10.12-linux-x64.tar.gz
The best part about this is you can repeat the pattern for any other version of node, change the current symlink at any time to switch which version you're running, and you're good to go
% node --version
v0.10.12
% npm --version
1.2.32
# switch versions to (e.g.) 0.10.5
% cd ~/.nodes && rm current && ln -s 0.10.5 current
% node --version
v0.10.5
% npm --version
1.2.18
Additional pointers when writing executable scripts
Make an executable file
% touch ~/somefile && chmod +x ~/someifle && nano ~/somefile
File contents
#!/usr/bin/env node
console.log(process.version);
Run it
% ./somefile
v0.10.12
You are running a much-too-old version of node and npm. You have node v0.5 which is very out of date. Upgrade to node v0.10 and things will work.
Modern node.js versions for Ubuntu are available via this PPA from Chris Lea
To install:
sudo apt-get install python-software-properties
sudo add-apt-repository --yes ppa:chris-lea/node.js
sudo apt-get install nodejs
UPDATE
It looks like your old version of node is installed at /usr/local/bin/node. The new version from the Chris Lea PPA will be at /usr/bin/node. So to verify all is well, do:
/usr/bin/npm --version #Should be approx 1.2
/usr/bin/node --version #should be approx v0.10
/usr/bin/npm install -g express
You should uninstall the local node, or fix your PATH:
export PATH=/usr/bin:$PATH

Resources