Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Create Your Own Node Module

mycoolmodule/index.js
export.a = "AAAAAA;
exports.hw = function() {
  console.log("Hello World!");
}
/*you can exports as many variables and functions as you want*/

routes/index.js
var express = require('express');

var mymodule = require('mycoolmodule')

var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
	mymodule.hw();
/*	console.log(mymodule.a) will yield AAAAAA*/
});
 
module.exports = router;
Comment

Create Your Own Node Module

cd node_modules
mkdir myCoolModule
cd myCoolModule
touch index.js
npm init
(answer yes to all)
exports.? all functions and variables you want to be used in other places.
/*for react*/

import {?1, ?2} from 'myCoolModule'
/*for expressJS*/

const myCoolModule = require('myCoolModule');
myCoolModule.?1
myCoolModule.?2
Comment

PREVIOUS NEXT
Code Example
Javascript :: react-navigation 
Javascript :: react chartjs 
Javascript :: set javascript 
Javascript :: substr javascript 
Javascript :: numeral js 
Javascript :: detect if user is online react 
Javascript :: angular object sort by key 
Javascript :: js set 
Javascript :: How To Generate a Table With JavaScript 
Javascript :: settimeout js 
Javascript :: find object from list 
Javascript :: jest cannot find module 
Javascript :: back button event listener javascript 
Javascript :: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0 
Javascript :: mongoose in nodem js 
Javascript :: discord.js messageUpdate 
Javascript :: jquery get element by tag 
Javascript :: get file extension in javascript 
Javascript :: run file with nodemon 
Javascript :: pass data ino pug nodejs 
Javascript :: sum float values in jquery 
Javascript :: add font awesome with nextjs 
Javascript :: print in javascript 
Javascript :: sequelize manual model/index.js 
Javascript :: export function javascript 
Javascript :: how to convert react component to image 
Javascript :: useroutes how to use 
Javascript :: uirouter 
Javascript :: _.escape underscore 
Javascript :: can we fine a key with help of value in array of objects javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =