Express module not found during installation using NPM

When I try to run the app.js file created by the expression, I get the following error:

$ node app.js node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: Cannot find module 'express' at Function._resolveFilename (module.js:320:11) 

When I print the expression 'express -version', I get a 2.3.3 return statement. I used npm to install express. I had to manually make npm using the following instructions:

 git clone http://github.com/isaacs/npm.git cd npm sudo make install 

Error Error: Cannot find module 'express' .

Do I need to do something after installing npm and the expression in order to explicitly see the modules created by npm?

My node - version: 0.4.6 My express - this version: 2.3.3 My npm version - version: 1.0.6

Express is installed globally. I used the -g flag to set it.

Edit: When I try to execute node -e require.paths, I get:

['/home/user/.node_modules', '/home/user/.node_libraries', '/ usr / local / lib / node']

So node does not detect the npm installation. How do I get node to detect an npm installation?

+44
javascript npm express
May 7 '11 at 7:08
source share
14 answers

I had the same problem. This worked for me though:

It seems that npm (now?) /usr/local/lib/node_modules/ node modules on /usr/local/lib/node_modules/ , rather than /usr/local/lib/node/

What I did was just copy everything from node_modules to node: sudo cp -r /usr/local/lib/node_modules/* usr/local/lib/node/ and now it works for me.

Hope this helps you :-)

+8
May 08 '11 at 22:44
source share
  • Install express

    npm install -g express

  • Create a new application

    express your_app

  • cd to application directory

    cd your_app

  • use npm link to solve modules

    npm link express

+67
Aug 29 '11 at 12:13
source share

Use local installations for require () and global installations for command line applications.

If you need both options, use the npm link command.

+27
Aug 04 2018-11-18T00:
source share

In Ubuntu 12.04, you need to add export NODE_PATH=/usr/local/lib/node_modules to your /.bashrc to use globally installed modules.

+20
Aug 09 '12 at 16:05
source share

It seems that while npm has been updated to install global modules in / usr / local / lib / node_modules, Node's own require.paths does not yet reflect this change.

There are two reasonable solutions:

1. Add the following code to the top of the application:

 require.paths.push('/usr/local/lib/node_modules'); 

Pro: non-invasive, easy to add

Con: discipline required, future versions of Node restrict access to require.paths

2. As root, do:

 ln -s /usr/local/lib/node_modules /usr/local/lib/node 

Pro: reasonably non-invasive

Con: requires root, modifies linux fs, system update may not be saved

+15
May 13, '11 at 22:27
source share

What about NODE_PATH=/usr/local/lib/node_modules in .bashrc or .bash_profile? I think this is the right way.

+6
Oct 22 2018-11-23T00:
source share

It may happen that if you use windows, the NODE_PATH environment variable is not set, and thus, libraries will not be found when executing node fileName.js. Check the variable on the console, and if not, create it. Give it the value NODE_HOME \ node_modules, where NODE_HOME is your node installation directory. This path is where npm install places each module at boot time.

+2
Mar 08 '12 at 18:50
source share

Set NODE_PATH=NODE_HOME\node_modules .

I am using Windows 7 and it works great.

+2
Jun 18 '12 at 4:00
source share

require.paths is removed, use the NODE_PATH environment variable instead.

+2
30 Oct
source share

It seems like the easiest way to do this is to run npm install from your application folder. This says npm connects everything.

This is the last statement after express <appname> :

 ... dont forget to install dependencies: $ cd <appname> && npm install 
+1
Nov 11 '11 at 4:30
source share

for all expression problems with mac computer:

Decision:

1.- tell your user the .npm folder:

sudo chown -R Webmaste / Users / webmaste / .npm /

  • In the test folder or in the folder:

sudo npm install -g express@2.5.8

  • Call express from your actual location:

/ Usr / local / shares / nmi / bin / express

4: sudo cd. && npm install

5: finally:

node application




The final message in the console should look like this:

Express server listening on port 3000 in development mode

0
Jan 28 '13 at 16:42
source share

for Mac users

 cd /usr/local/lib/node sudo ln -s ../node_modules/* ./$1 
0
Jul 27 '13 at 7:45
source share

I installed gulp , and when I ran this gulp command on the command line, I got a gulp: command not found error. It turned out that he installed gulp in my local folder /home/YOURUSERNAME/.node/lib/node_modules , and not in the npm global folder.

You can check the npm root folder by running this command: npm root -g , which returned my personal directory /home/YOURUSERNAME/.node/lib/node_modules , rather than the expected /usr/local/lib/node_modules .

You can fix this by running the npm config set prefix /usr/local command.

0
May 18 '15 at 17:10
source share

Finally, with Linux, a good way is to use the command: sudo apt-get install node-express

But with expression 4, we must use the express generator to create the skeleton of the application, install it using "npm install express-generator -g", and then run the command "express myapp". see also install express

0
Feb 20 '16 at 20:29
source share



All Articles