NPM is refusing to acknowledge all commands currently

When I try to run the command below:

npm install nodemon -g

The output shows:

/home/ubuntu/.node/bin/nodemon -> /home/ubuntu/.node/lib/node_modules/nodemon/bin/nodemon.js
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b9b8b3b2bab8b997e6f9e5f9e6">[email protected]</a> /home/ubuntu/.node/lib/node_modules/nodemon
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3cecacdcacec2d7c0cbe3938d908d93">[email protected]</a> (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="512238363c243f3511607f617f61">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9c5dbdc84cac8cac1cce99b879c8799">[email protected]</a>)
├── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0a09570e081f1f3a4a544a5449">[email protected]</a> (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2d7c4d7dcc69fc1c6c0d7d3dff2829c879c81">[email protected]</a>)
└── <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94e1e4f0f5e0f1b9fafbe0fdf2fdf1e6d4a4baa5baa5a4">[email protected]</a> (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="394a5c544f5c4b790b170a170b">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="accfc4cdc0c7ec9c8298829c">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9dad6d7dfd0decacdd6cbdcf989978a9788">[email protected]</a>, <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e5c4b5f5b4b5d5a6e1c001a17001e">[email protected]</a>)

However, after installing any node package like forever as shown below:

npm install forever -g

I encounter an issue accessing the newly installed commands such as nodemon where it says:

nodemon: command not found

Strangely, I can run them if referencing the file directly like this with forever:

/home/ubuntu/.node/lib/node_modules/forever/bin/forever server/app.js &

This works just fine. Any idea why? How can I fix this issue?

Looking at my profile...

  GNU nano 2.2.6                            File: /home/ubuntu/.profile                                                               

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
    export PATH = /home/ubuntu/.node/bin:$PATH

fi

Command outputs! :

echo $PATH:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

And when running ls -la:

ls -la
drwxrwxr-x 2 ubuntu ubuntu 4096 Dec  6 14:42 .
drwxrwxr-x 4 ubuntu ubuntu 4096 Dec  6 12:24 ..
lrwxrwxrwx 1 ubuntu ubuntu   39 Dec  6 14:42 forever -> ../lib/node_modules/forever/bin/forever
lrwxrwxrwx 1 ubuntu ubuntu   42 Dec  6 14:19 nodemon -> ../lib/node_modules/nodemon/bin/nodemon.js

Suddenly, upon restart, I get these error messages:

-bash: export: `=': not a valid identifier
-bash: export: `/home/ubuntu/.node/bin:/home/ubuntu/.node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games': not a valid identifier

Answer №1

Looks like your Node.js installation is acting up

Here are the steps to install Node.js from source on OSX or Linux:

NOTE - This method installs both node and npm together in a single release.

To start fresh, remove any prior installations of node and npm along with the following:

sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm   ~/.npm_ignore
sudo mv ~/tmp    ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore

Download the source code from: https://nodejs.org/en/download/stable/
or select a specific release from https://nodejs.org/download/release

Once downloaded, navigate into the directory containing the source code

cd node-v5.5.0  # or whatever current version is

It is recommended to run the following commands as yourself and not as root (sudo)

Choose one of the following NODE_PARENT locations to specify where Node will be installed:

export NODE_PARENT=/some/desired/install/path_here
export NODE_PARENT=/usr/local/bin/nodejs   # Use only if necessary to install as root
export NODE_PARENT=${HOME}/nodejs-v0.10.33 # Recommended choice

export PATH=${NODE_PARENT}/bin:${PATH}      # Ensure executables can be found
export NODE_PATH=${NODE_PARENT}/lib/node_modules # Set location for Node modules 

./configure   --prefix=${NODE_PARENT}

make
make install

This will install Node.js in the directory specified by --prefix

When using syntax: npm install -g some_cool_module the -g flag installs globally in $NODE_PATH rather than in the current directory

IMPORTANT - Add the three export xxx=yyy commands mentioned above to your ~/.bashrc or similar file to persist these environment changes

Answer №2

Make sure to include /home/ubuntu/.node/bin in your PATH environment variable.

For example, in either your .profile or .bashrc file, add the following line:

export PATH = /home/ubuntu/.node/bin:$PATH

* UPDATE *

It is recommended not to place the updated path within the if statement, as these are separate concerns (the existence of a home bin and configuring the node module path).

Additionally, do not forget to reload your .profile after making changes:

source /home/ubuntu/.profile

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble resolving '___' from the 'home' state? Dealing with an angular ui-router complication?

I am a newcomer to angular and currently following the instructions outlined in this tutorial: https://scotch.io/tutorials/angularjs-multi-step-form-using-ui-router However, I am facing challenges while injecting this module into an existing module. Des ...

What is the best way to organize an Express application that handles both API requests and views?

Currently, I am in the process of developing a small application that will function as both a website and its API. To achieve this, I am utilizing Node, Express, and Webpack. The structure of my directory is organized as follows: >client |>dist ...

The procedure for deleting npm and node package on a Mac system

Currently, I am struggling to completely remove the npm and node packages that I initially installed in order to replace them with the Homebrew version. Can someone provide me with guidance on how to successfully eliminate the package versions of node.js a ...

Is it necessary to utilize ngrok to expose both front and back ends in a MERN stack in order for CRUD operations to function properly?

Currently, I am working on developing a MERN app on my local machine. The front end portion of the application can be accessed at localhost:3000 While the back end is running on localhost:3003 In the front end code, there is a request configured as: ax ...

Issue: The --outFile flag only supports 'amd' and 'system' modules

Encountering an issue while trying to compile an Angular project in Visual Studio Code using ng build and then serving it with ng serve Unfortunately, faced the following error message in both cases: The error 'Only 'amd' and 'syste ...

Error: Callback function in Mongoose Populate is returning undefined

I have a query set up in MongoDB where I am trying to display all subcollections of the schema while excluding the account ID. The issue is that I am getting "undefined" as the result for the callback "list_data". Here is how my query looks in my routes: ...

Is it feasible to utilize Google Calendar API for JavaScript through npm install? Alternatively, can the Google Calendar API be utilized for Node.js in the browser within Next.js?

Looking to integrate the Google Calendar API as a library in your Next.js project without using _document.tsx? I have explored two potential approaches for achieving this: Utilize the google calendar api for JavaScript by installing it via npm Use the goo ...

How can I sync changes between two variables in node.js?

Is there a method to create a shared variable in JavaScript? Here is an example of what I am attempting to achieve: var id = 5; var player = new Player(id); var array1[0] = player; var array2[0] = player; array1[0].id = 8 console.log(array1[0]); // ...

"Every time I try to use passport-jwt in my Node.js application,

Check out this code snippet featuring demo credentials: const express=require('express'); const app=express(); const bodyparser=require('body-parser'); const passport=require('passport'); const morgan=require('morgan&apo ...

Move the dist folder to the libs directory using webpack

I am interested in achieving the following task: After successfully using gulp for copying libraries, I added the below code to my tasks: gulp.task('copy:libs', function() { return gulp .src(npmdist(), { base: paths.base.node.dir }) . ...

IDE cannot find imported modules even though the NPM Package is functioning correctly

Working with npm has been a great experience for me, and my first package is functioning perfectly. However, in my IDE (Webstorm), when I import my package, it shows a "Cannot resolve symbol" error (even though it works). Furthermore, when I use ...

Protecting my HTTP connections

Currently, I am working on my Home Automation project and here is how the setup looks like: An ESP8266 WiFi module will be connected to a variety of sensors. The module will run a light web server while a Linode Cloud will host specific NodeJS scripts a ...

Is there a way to send URL variables to express.js similar to how it's done in PHP?

Currently in the process of converting my PHP website to Express.js. There are numerous scripts on my frontend that generate links in the format page.php?id=10&something=anything. Is there a way in Express.js to capture variables from URLs structured ...

What reasons underlie the existence of various methods for importing Modules in JavaScript?

I'm confused about the distinctions when it comes to importing a JavaScript module in various ways such as: CommonJS ES5 ES6 NodeJS Typescript What is the reason for having multiple methods of importing JavaScript modules? Is the concept of a "modu ...

In Sequelize, the "afterBulkCreate" hook consistently provides the most recent values in the _previousDataValues, particularly when utilizing updateOnDuplicate to modify specific columns

Table.addHook('afterBulkCreate' , async (params , options) => { console.log("Table.afterBulkCreate ~ params:", params , options) }) const st1 = await Table.bulkCreate(params, { updateOnDuplicate: ["metrics", ...

Encountering a Troubleshooting Issue with ArcGIS JS API 4.7 and N

Recently, I have been attempting to set up ArcGIS JS API 4.7 using npm for a Vue.JS project. However, when I execute the command npm install arcgis-js-api I encounter an error with NPM: npm ERR! code E404 npm ERR! 404 Not Found: @dojo/i18n@~0.6.0 Althou ...

The anchor tag fails to trigger the onClick function in React

I'm having trouble updating the component state in my React app when clicking on an anchor tag within the render method. I've attempted to bind the function in the constructor, but the console.log statement is still not being called. Here's ...

The command line utility for webpack encountered an unfamiliar argument: --output

Here are my npm and node.js versions: https://i.stack.imgur.com/BOkSi.png Whenever I attempt to run the npm dev command: https://i.stack.imgur.com/ozlKy.png The log file shows: 0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/no ...

Twilio's phone calls are programmed to end after just 2 minutes

For the past week, I've been dealing with a frustrating issue where calls are being automatically disconnected after 2 minutes of recording. Here is the TwiML code: <Response> <Say voice="woman" language="en">Hii Welcome to our App</Sa ...

403 Forbidden - PUT https://registry.npmjs.org/shah - Access Denied: You are not authorized to release the package "shah". Please ensure you are logged in with the appropriate credentials

Currently in the process of developing a reactjs component library for npm. I've followed all the necessary steps, but encountering an issue when trying to publish via npm. Despite spending over an hour searching on Google, I haven't been able t ...