I have Node JS installed on my system, how can i configure local server using node js without wamp or xampp so that i can run my applications in my local machine? can somebody help me with the step by step procedure?
-
Your get or write a small node.js app that runs a web server (takes about 10 lines of code) and then you start that app. node.js is NOT a web server itself. It can run apps that are web servers once you have such an app. Express is a node.js framework that makes web servers pretty easy. Here's a simple example web server in Express: expressjs.com/en/starter/hello-world.htmljfriend00– jfriend002016-03-17 06:25:56 +00:00Commented Mar 17, 2016 at 6:25
Add a comment
|
2 Answers
Node JS makes it really simple to create a server. All you need to do is write a file : server.js.
var http = require("http");
var server = http.createServer(function(request, response) {
response.end('Hello World!');
});
server.listen(8000);
console.log("Server is listening");
Open cmd and write
node server.js
Go to your browser and open
localhost:8000
That should work!
Comments
Try this one for configure local server without wamp || Xampp
var http = require('http'); // 1 - Import Node.js core module
var server = http.createServer(function (req, res) { // 2 - creating server
// handle incoming requests here..
});
server.listen(5000); //3 - listen for any incoming requests
console.log('Node.js web server at port 5000 is running..')
1 Comment
giusti
Please format your code by prepending with four spaces, or select the code and click the
{} button in the edit page.