Answers for "module.exports in node js"

29

What is the syntax to export a function from a module in Node.js

function foo() {}
function bar() {}

// To export above functions:
module.exports = foo;
module.exports = bar;

// And in the file you want to use these functions,
// import them like this:
const foo = require('./module/path');
const bar = require('./module/path');
Posted by: Guest on January-26-2020
0

using multiparty with node js express

var express = require('express');
var multiparty = require('connect-multiparty'),
    multipartyMiddleware = multiparty({ uploadDir: './imagesPath' });

var router = express.Router();

router.post('/', multipartyMiddleware, function(req, res) {
  console.log(req.body, req.files);
  var file = req.files.file;
  console.log(file.name);
  console.log(file.type);
  res.status(200).send('OK');
});

module.exports = router;
Posted by: Guest on May-05-2020
1

writefile in node js

fs.writeFile('2pac.txt', 'Some other lyric', 'ascii', callback);
Posted by: Guest on March-15-2020
1

Example: Export a function in Node

function add(a,b){
return a + b;
}

function sub(a,b){
return a - b;
}

function mul(a,b){
return a * b;
}

function div(a,b){
return a / b;
}

exports.add = add
exports.sub = sub
exports.mul = mul
exports.div = div
Posted by: Guest on June-15-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language