Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:01:11+00:00 2026-05-17T03:01:11+00:00

Theory: One of the things that appeals to me about node.js is using it

  • 0

Theory:

One of the things that appeals to me about node.js is using it as a command line tool.

In theory, I can write libraries in Javascript and place them in my ~/.node_libraries directory, and then then I can reuse those libraries.

So for instance, I have a text.js in ~/.node_libraries, and it has a bunch of text-related functions I use over and over (depunctuate(), tokenize_text(), things like that).

The beauty of this is that I could use the same text.js file with my command-line scripts and server side. Right now I’m doing all that text processing stuff with Python, but I’d like to just stick to one language.

Practice:

AFAICT, in order to create a node.js module, I have to attach everything that I want to be available to exports or this. I.e., in text.js, I have to do:

exports.depunctuate = depunctuate

or

this.depunctuate = depunctuate

If I use exports, I have problems with using the library server-side à la:

<script src=text.js></script>

because then I get exports is not defined errors.

If I use this, I avoid the error, but everything I export ends up getting attached to the window object.

Is there some way I can set up these libraries that avoid both of these problems? For instance, is there some way I can wrap the exporting of exports so that the var will be apparent to node, but not when it’s used in a plain Javascript file on a server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:01:12+00:00Added an answer on May 17, 2026 at 3:01 am

    How about testing for the existence of the exports object before sticking stuff in it?

    This has worked well for me so far, but maybe there are better ideas out there:

    if(typeof(exports) !== 'undefined' && exports !== null) {
      exports.foo = foo;
      exports.bar = bar;
    }
    

    In CoffeeScript, this can be done a little more tersely:

    [exports.foo, exports.bar] = [foo, bar] if exports?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got 2 jQuery functions. One calls the other (in theory...). These are: $.testFunction
In theory in layered architecture you can have multiple modules on the same layer.
In theory this seems easy but I just can't get my head around this...
In informatics theory I hear and read about high-level and low-level languages all time.
As far as theory goes it seems that Asp.net MVC framework could better be
I understand the theory behind the factory design pattern now, but can't seem to
This is more of a cryptography theory question, but is it possible that the
I work on a 100% Javascript site that uses a CSS class on the
So here is one of the simplest things one might do: Random rng =
I'm working on a custom panel control and one of the things I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.