First, install node.jsalong the nextpath. You can also customize it to add the directory of node.exe to the system environment variable.
Create a project: d:/project
Cd d:/project
Then run npm install socket. io to see the newly produced node_module directory under this directory,
Set up server. js as follows:
var io = require('socket.io').listen(8080);io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); });});
Then, create the index.html file under Directory: D: \ project \ node_modules \ socket. io \ lib.
The content is as follows:
Test nodejs <Script src = "http: // localhost: 8080/socket. io/socket. io. js "> </script> <script> var socket = io. connect ('HTTP: // localhost: 100'); socket. on ('News', function (data) {console. log (data); socket. emit ('My other event', {my: 'data'}) ;}); </script>
Test the use of node server. js and then click the javasindex.html file to open the Chrome review element ..
Set global node_module. Create a new node-global File under the node installation directory to modify the npmrc file under npm.
Prefix = D: \ software \ node-global
Run
Npm config set prefix "D: \ software \ node-global"
Npm config set cache "D: \ software \ node-cache"
Add node_global to NODE_PATH and PATH
Then you can run server. js globally.