简体   繁体   中英

Not able to run node.js program in command prompt

error on executing the program I am beginner to node.js .I have followed all the steps from the below blog:

http://blog.teamtreehouse.com/install-node-js-npm-windows

I got the node version and npm version too. But not getting the output when I try to run the js file from cmd.

console.log('Node is installed!');

the content of the js file is mentioned in the above line.

Please help me out!!

Thanks in advance

Its Seems there is no hello.j s in c drive or in wrong directory

Goto any folder and make your hello.js and then navigate to that folder in cmd then write

node hello.js  // .js is optional 

在此处输入图片说明

in the picture above you can i receive error helloo cant find module becoz i dont have any file with name helloo.js

suppose your file is in D drive then goto D drive and wirte

在此处输入图片说明

Your can make simple hello.js server

//Lets re   quire/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080; 
//We need a function which handles requests and send response
//Create a server
var server = http.createServer(function (request, response){
    response.end('It Works!! Path Hit: ' + request.url);
});
//Lets start our server
server.listen(PORT, function(){
    //Callback triggered when server is successfully listening. Hurray!
    console.log("Server listening on: http://localhost:%s", PORT);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM