Reputation: 51
I'm installed nodejs on my ubuntu 14.04 machine. When i ran node --version it gives me v4.4.2. I have install npm with version 3.9.2. When i run command npm install -g express it gives following output install express js
After completing the process, when I try to check express version it tells that The program 'express' is not installed try apt-get install node-express. Can somebody tell me where I'm doing wrong
Upvotes: 0
Views: 3277
Reputation: 4547
First open terminal by 'ctrl + alt + t'
- Check nodejs is installed or not by command :- node -v
- Inter following path into terminal :- cd /var/www/html
- Create new folder (manually) or by command line :- mkdir nodeTest
- Enter in "nodeTest" folder :- cd nodeTest
- Create 'package.json' :- npm init //initialize node project (nodeTest)
- install Express :- sudo npm install express --save
Now open the 'nodeTest' folder from following path in your system :- /var/www/html/nodeTest
Now create :- index.js
index.js
var express = required("express");
var app = express();
app.get("/", function (req, res) {
res.send(" Welcome Node js ");
});
app.listen(8000, function () {
console.log("Node server is runing on port 8000...");
});
Runnig node server by terminal command :- node index.js
Now check url :- "localhost:8000"
Upvotes: 1
Reputation: 203304
The tutorial you're following is outdated.
Previous versions of Express came with a command line tool called express
, which you could use to create an application skeleton. However, since Express 4 was released (a while ago), this command line tool has been removed from the regular express
package and moved to a separate package called express-generator
.
To install this package, use this:
$ npm install express-generator -g
This should install the express
command line tool (however, since the tutorial is outdated you may run into additional problems).
Upvotes: 0
Reputation: 3399
As I said in my comment, ExpressJS it's a framework for developing servers. It's not a server by itself.
You should create a npm project (with npm init
) and you can install it as a dependency with npm install express --save
. Then refer to the "Hello World" example to see how to create a simple server: Hello World Starter
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Also, you may want to serve static files by using
app.use(express.static('name_of_the_directory'));
Upvotes: 0