Create a Node.js Website – Opensite - Digital Solutions Agency

0422 374 731 info@opensite.com.au

Create a Node.js Website

Last update:

Tutorials ,

Create the project folder using the CLI.

cd ~/projects
mkdir mysite
cd mysite

Initialise the project (wizard for building package.json).

 npm init 

Create app file (the primary application)

// mac
touch app.js

// windows
copy nul app.js

Install Express

 npm install express --save 

Note:

// add to dependencies
--save

// add only to dev
--save-dev

Require Express by adding this to app.js

const express = require('express');
const app = express();

Test Express by adding this to app.js

app.listen(3000, function() {
 console.log('listening on 3000')
})

Run

node app.js

Then navigate to localhost:3000 in your browser. You should see “Cannot GET /”. This means our application is working, we’re communicating with our Express server through the browser.