Reputation: 1362
I just started learning Node js, First I installed node,npm, express
I want to work in npm, but I don't know how to start. The command I gave in terminal was
sh-4.2$ cd new/
sh-4.2$ express new-project
sh-4.2$ cd new/
sh-4.2$ express new-project
sh-4.2$ node app
But I was not able to connect in localhost:3000
Upvotes: 1
Views: 1612
Reputation: 66
Try this command in your project folder after you've generated the project:
node bin/www
The code to run the server is placed in this file.
Upvotes: 2
Reputation: 76189
I dislike automatic project generators so here is how to create a new express project manually.
Create new folder:
mkdir myNewApp
cd myNewApp
Create a new package.json (makes managing dependencies much easier) - just press enter to all questions, you can change these things later:
npm init
Install express and save it in our package.json:
npm install express --save
Create our main server file:
touch server.js
And paste the following:
var express = require('express'),
server = express();
server.get('/', function (req, res) {
res.send('hello world');
});
server.listen(3000);
Now start it:
node server.js
And visit http://localhost:3000
in your browser.
Upvotes: 2