very new to nodejs, tried to build a very simple server on a linux server. for some reason when I go to the url I see the files in the folder. I am learning so I created a folder for each learning exercise.
This is my code: server.js
var express = require('express');
var bodyParser = require('body-parser');
var path = require('path');
var port = 3000;
var app = express();
app.use(function(req, res, next){
console.log('Time: ', Date.now());
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(req, res){
res.send('Hello World!');
});
app.get('/about', function(req, res){
res.send('About Page');
});
app.listen(port);
console.log('Server started on ports '+port);
module.exports = app;
This is package.json
{
"name": "myexpress",
"version": "1.0.0",
"description": "Simple express application",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "*",
"body-parser":"*"
}
}
I run node server
in the folder project, I receive the Server running on ports3000
massage but in the browser i see this:
any help could be great,
via DavSev
No comments:
Post a Comment