Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express doesn't work on ubuntu

I'm new with nodejs and trying to learn it. I have installed node framework express as global module by command:

$ sudo npm install express -g

This works correctly and I have it in /usr/lib/node_modules. Then I'm creating a new project on express:

 $ express app

But this doesn't create project folder and does not return any error code, clear node code works fine. Anybody knows how to detect and fix this error?

like image 664
Andrii Tarykin Avatar asked Dec 10 '13 20:12

Andrii Tarykin


People also ask

Can not install Express?

To solve the error "Cannot find module 'express'", install the package by running the command npm install express in the root directory of your project. If you don't have a package. json file, create one by running npm init -y . The error occurs when we try to import the express package without installing it.

How do I start Express in Terminal?

js const express = require('express') // Create Express app const app = express() // A sample route app. get('/', (req, res) => res. send('Hello World! ')) // Start the Express server app.

Do I need to install Express for every project?

Yes, install Express and other NPM components separately for each project. This way, you keep each project independent from the others and you can upgrade components in one without affecting all the others. Each project then has its own package.


2 Answers

found it. the npm package is actually named express-generator

sudo npm install -g express-generator

you can then use

express mytestapp

that results in :

olivier@****:~/workspace$ express mytestapp

create : mytestapp
create : mytestapp/package.json
create : mytestapp/app.js
create : mytestapp/public
create : mytestapp/public/javascripts
create : mytestapp/public/stylesheets
create : mytestapp/public/stylesheets/style.css
create : mytestapp/routes
create : mytestapp/routes/index.js
create : mytestapp/routes/users.js
create : mytestapp/views
create : mytestapp/views/index.jade
create : mytestapp/views/layout.jade
create : mytestapp/views/error.jade
create : mytestapp/bin
create : mytestapp/bin/www
create : mytestapp/public/images

install dependencies:
 $ cd mytestapp && npm install

run the app:
 $ DEBUG=my-application ./bin/www

Cheers ! Olivier

Source : http://expressjs.com/guide.html#executable

like image 144
olivieryem Avatar answered Nov 01 '22 06:11

olivieryem


For me the solution was simply to install the nodejs-legacy package:

sudo apt-get install nodejs-legacy
like image 41
codefreak Avatar answered Nov 01 '22 04:11

codefreak