Skip to content

bux225/simple_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a simple node.js server. Here's how it was created from scratch

  1. mkdir simple_server
  2. cd simple_server
  3. npm_init
  4. fill out the package.json info. use main.js as entry point
  5. npm i http-status-codes -S installs needed node_modules
  6. make a main.js file
  7. copy the following code into main.js
const port = 3000,
  http = require( 'http' ),
  httpStatus = require( 'http-status-codes' ),
  app = http.createServer( ( request, response ) => {
    console.log( 'Received an incoming request!' );
    response.writeHead( httpStatus.OK, {
      'Content-Type': 'text/html'
    } );

    let responseMessage = '<h1>Hello, Universe!</h1>';
    response.write( responseMessage );
    response.end();
    console.log( `Sent a response : ${responseMessage}` );
  } );

app.listen( port );
  console.log( `The server has started and is listening on port number: ${port}` );
  1. add a .gitignore file in main directory
  2. add node_modules/ to .gitignore
  3. in terminal, run 'node main' to started
  4. open browser to localhost:3000
  5. should see "Hello, Universe"

About

Simple Node.js server template

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published