NODE JS and EXPRESS Tutorial 1

NODE JS and EXPRESS Tutorial 1

First lets install Express after we have installed Node.


1
npm install express

Let us again make our index.html file


1
2
3
4
5
6
7
var fs = require('fs');

//   MAKE NEW FILE NAMED INDEX.HTML
fs.open('index.html', 'w', function (err, file) {
  if (err) throw err;
  console.log('SAVED NEW INDEX.HTML FILE');
});

And append some new HTML


1
2
3
4
5
// APPEND FILE INDEX.HTML
fs.appendFile('index.html', 'new text', function (err) {
  if (err) throw err;
  console.log('APPENDING INDEX.HTML FILE');
});

Lets start our Express server and serve the file.


1
2
3
4
5
6
7
8
9
10
var express = require("express");
var app     = express();
var path    = require("path");

app.get('/',function(req,res){
  res.sendFile(path.join(__dirname+'/index.html'));
});

app.listen(3000);
console.log("Running at Port 3000");

Related posts

One Thought to “NODE JS and EXPRESS Tutorial 1”

  1. I was just telling my friend about that.

Comments are closed.