-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
  • 8,652
  • 9
  • 48
  • 78
  • 1
    You've provided no code, no way to know what your code is doing. The best thing to do would be to add the code inside `index.js` so people can give you an accurate answer. – peteb Nov 23 '16 at 17:38
  • 1
    Does your index file actually take keyboard input? That would be unusual for a web app. – jeff carey Nov 23 '16 at 17:39
  • @peteb, done thx! – usefulBee Nov 23 '16 at 17:41
  • @jeffcarey, updated the question with code example – usefulBee Nov 23 '16 at 17:41
  • 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
  • @SebastiánEspinosa you can add this as an answer if you would like to, and I will accept it whenever the system permits. – usefulBee Nov 23 '16 at 17:53

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,030
  • 12
  • 23