Starting a node.js server

I recently got into node and I installed it on my localhost. I am using WAMP. I am on Windows Vista.

Anwyay, I installed it. I made a new file in my localhost directory with this being called server.js

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {
        'Content-Type': 'text/plain',
        'Access-Control-Allow-Origin' : '*'
    response.end('Hello World\n');

then I went to node and tried typing % node server.js and all I got was an ellipses. What gives?

UPDATE: I checked my Systems variable and saw that my PATH lists the node.js as C:\Program Files (x86)\nodejs\

enter image description here

Run cmd and then run node server.js. In your example, you are trying to use the REPL to run your command, which is not going to work. The ellipsis is node.js expecting more tokens before closing the current scope (you can type code in and run it on the fly here)

The NodeJS code that you wrote is corrected, and it should work but as @dwerner said you have to write node server.js in the command prompt not inside the Node REPL.

But today most of who work with NodeJS are developing using a development environment (IDE). By using IDE you get a hotkey for running your code, and many things that can help you in the daily development (Syntax highlight for e.g.)

One of the most popular IDE’s today for NodeJS development is VSCode, you can check it out.

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   How to do a deep comparison between 2 objects with lodash?

Similar Posts