-2

Below the last line, the command is flashing as expected, yet I can't write any commands. I could restart the program but that does not solve the problem indefinitely. What is wrong??

Code is based on the following tutorial:

NodeJs Tutorials: Mastering NodeJS, Part 1: Introduction to Node

'use strict'

const http = require('http');
const express = require('express');
const fs = require('fs');

const configJson = fs.readFileSync('./config.json');
const config =  JSON.parse(configJson);

const app = express();

app.use(express.static(config.webServer.folder));

const httpServer = http.createServer(app);

httpServer.listen(config.webServer.port, function(err){
if(err) {
    console.log(err.message);
    return;
}
console.log(`web server on port ${config.webServer.port}`);
});

enter image description here

usefulBee
  • 9,250
  • 10
  • 51
  • 89
  • 2
    This happens because your code is still running (the httpServer.listen function is waiting new connections on the 3001 port), you can kill the execution with Ctrl + C, but this is normal behavior, this should happen. – Sebastián Espinosa Nov 23 '16 at 17:45
  • You might find this useful: http://stackoverflow.com/questions/8549145/execute-some-code-and-then-go-into-interactive-node – jeff carey Nov 23 '16 at 17:46
  • @SebastiánEspinosa, That is exactly it (Ctrl + C) and that is what the author of the tutorial probably did without mentioning how he did it. – usefulBee Nov 23 '16 at 17:47

1 Answers1

1

This happens because your code is still running (the httpServer.listen function is waiting new connections on the 3001 port), you can kill the execution with Ctrl + C, but this is normal behavior, this should happen.

Sebastián Espinosa
  • 2,123
  • 13
  • 23