Use C++ to write extension modules for node.js
Prerequisite: Install node.js, Python2.7 and visual studio 2013.
Process:
First install the GYP project generation tool, npm install -g node-gyp.
Create the test directory, which is our working directory. Create a src directory under this directory to store the C++ source code. Create a new text file named binding.gyp. This is the gyp project file. The content is as follows:
{ 'targets':[{ 'target_name':'hello', 'sources':['src/hello.cc'] }] }
Write a simple hello.cc with the following content:
#include <node.h> using namespace v8; Handle<Value> Hello(const Arguments& args) { HandleScope scope; return scope.Close(String::New("Hello world!")); } void init(Handle<Object> target) { NODE_SET_METHOD(target, "hello", Hello); } NODE_MODULE(hello, init)
Then run the command: node-gyp configure
If run correctly, a directory ----build will appear, under which vs2013 is generated for you Project file, so that it can be edited and compiled in vs2013.
Of course, you can also directly use the command node-gyp build to compile.
The test js program is as follows:
var hello = require('./hello'); console.log(hello.hello());
Some problems were encountered and the records are as follows:
1. C:UsersAdministrator.node-gyp

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

